-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPassenger.java
72 lines (56 loc) · 1.66 KB
/
Passenger.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
public class Passenger {
// Instance variables
private String passengerName;
private String passengerCruise;
private String passengerRoomType;
// Constructor - default
Passenger() {
}
// Constructor - full
Passenger(String pName, String pCruise, String pRoomType) {
passengerName = pName;
passengerCruise = pCruise;
passengerRoomType = pRoomType; // should be BAL, OV, STE, or INT
}
// Accessors
public String getPassengerName() {
return passengerName;
}
public String getPassengerCruise() {
return passengerCruise;
}
public String getPassengerRoomType() {
return passengerRoomType;
}
// Mutators
public void setPassengerName(String tVar) {
passengerName = tVar;
}
public void setPassengerCruise(String tVar) {
passengerCruise = tVar;
}
public void setPassengerRoomType(String tVar) {
passengerRoomType = tVar;
}
// print method
public void printPassenger() {
int spaceCount;
String spaces1 = "";
String spaces2 = "";
spaceCount = 20 - passengerName.length();
for (int i = 1; i <= spaceCount; i++) {
spaces1 = spaces1 + " ";
}
spaceCount = 20 - passengerCruise.length();
for (int i = 1; i <= spaceCount; i++) {
spaces2 = spaces2 + " ";
}
System.out.println(passengerName + spaces1 + passengerCruise + spaces2 +
passengerRoomType);
}
// method added to print passenger's name vice memory address
@Override
public String toString() {
return passengerName;
}
}