-
Notifications
You must be signed in to change notification settings - Fork 0
/
Ship.java
96 lines (77 loc) · 2.04 KB
/
Ship.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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
public class Ship {
// Instance Variables
private String shipName;
private int roomBalcony;
private int roomOceanView;
private int roomSuite;
private int roomInterior;
private boolean inService;
// Constructor - default
Ship() {
}
// Constructor - full
Ship(String tName, int tBalcony, int tOceanView,
int tSuite, int tInterior, boolean tInService) {
shipName = tName;
roomBalcony = tBalcony;
roomOceanView = tOceanView;
roomSuite = tSuite;
roomInterior = tInterior;
inService = tInService;
}
// Accessors
public String getShipName() {
return shipName;
}
public int getRoomBalcony() {
return roomBalcony;
}
public int getRoomOceanView() {
return roomOceanView;
}
public int getRoomSuite() {
return roomSuite;
}
public int getRoomInterior() {
return roomInterior;
}
public boolean getInService() {
return inService;
}
// Mutators
public void setShipName(String tVar) {
shipName = tVar;
}
public void setRoomBalcony(int tVar) {
roomBalcony = tVar;
}
public void setRoomOceanView(int tVar) {
roomOceanView = tVar;
}
public void setRoomSuite(int tVar) {
roomSuite = tVar;
}
public void setRoomInterior(int tVar) {
roomInterior = tVar;
}
public void setInService(boolean tVar) {
inService = tVar;
}
// print method
public void printShipData() {
int spaceCount;
String spaces = "";
spaceCount = 20 - shipName.length();
for (int i = 1; i <= spaceCount; i++) {
spaces = spaces + " ";
}
System.out.println(shipName + spaces + roomBalcony + "\t" +
roomOceanView + "\t" + roomSuite + "\t" +
roomInterior + "\t\t" + inService);
}
// method added to print ship's name vice memory address
@Override
public String toString() {
return shipName;
}
}