-
Notifications
You must be signed in to change notification settings - Fork 0
/
CargoShip.java
47 lines (31 loc) · 1.15 KB
/
CargoShip.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
public class CargoShip extends Ship {
//Field for the Cargoship capacity
private int cargoCapacity;
//The constructor, and accessor and mutator methods below
public CargoShip(String shipName,
String yearBuilt,
int cargoCapacity) {
super(shipName, yearBuilt);
this.cargoCapacity = cargoCapacity;
}
public CargoShip(CargoShip other) {
super(other.getShipName(), other.getYearBuilt());
this.cargoCapacity = other.cargoCapacity;
}
public int getCargoCapacity() {
return cargoCapacity;
}
public void setCargoCapacity(int cargoCapacity) {
this.cargoCapacity = cargoCapacity;
}
//The override toString to display everything correctly,,, hopefully
@Override
public String toString() {
return "The cargo ship name is: " +getShipName() + ". \n The cargo capacity is: "+cargoCapacity+" tons.";
}
//Another override for the display() method from the Display interface
@Override
public void display() {
System.out.println(this.toString());
}
}