-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCruise.java
125 lines (100 loc) · 3.37 KB
/
Cruise.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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
/*
*
* @author Noah Pohl
* Cruise.java
*
*/
public class Cruise {
// Instance Variables
private String cruiseName;
private String cruiseShipName;
private String departurePort;
private String destination;
private String returnPort;
// Constructor - default
Cruise() {
}
// Constructor - full
Cruise(String tCruiseName, String tShipName, String tDeparture, String tDestination, String tReturn) {
cruiseName = tCruiseName;
cruiseShipName = tShipName;
departurePort = tDeparture;
destination = tDestination;
returnPort = tReturn;
}
// Accessors
public String getCruiseName() {
return cruiseName;
}
public String getCruiseShipName() {
return cruiseShipName;
}
public String getDeparturePort() {
return departurePort;
}
public String getDestination() {
return destination;
}
public String getReturnPort() {
return returnPort;
}
// Mutators
public void setCruiseName(String tVar) {
cruiseName = tVar;
}
public void setCruiseShipName(String tVar) {
cruiseShipName = tVar;
}
public void setDeparturePort(String tVar) {
departurePort = tVar;
}
public void setDestination(String tVar) {
destination = tVar;
}
public void setReturnPort(String tVar) {
returnPort = tVar;
}
// print cruise details
public void printCruiseDetails() {
// complete this method
// add spacing after Cruise name
// cruiseNameSpace variable will be used for appropriate spacing
String cruiseNameSpace = "";
int spaceCount = 20 - cruiseName.length();
// for loop to get required spacing
for (int i = 0; i < spaceCount; i++) {
cruiseNameSpace = cruiseNameSpace + " ";
}
// space out the cruise ship name
// cruiseShipSpace variable will be used for appropriate spacing
String cruiseShipSpace = "";
int cruiseShipCount = 20 - cruiseShipName.length();
// for loop to get required spacing
for (int i = 0; i < cruiseShipCount; i++) {
cruiseShipSpace = cruiseShipSpace + " ";
}
// add the necessary spacing after departure
// departureSpace variable will be used for appropriate spacing
String departureSpace = "";
int departureCount = 20 - departurePort.length();
// for loop to get required spacing
for (int i = 0; i < departureCount; i++) {
departureSpace = departureSpace + " ";
}
// finally add up the necessary spacing after destination
// destinationSpace variable will be used for appropriate spacing
String destinationSpace = "";
int destinationCount = 20 - destination.length();
// for loop to get required spacing
for (int i = 0; i < destinationCount; i++) {
destinationSpace = destinationSpace + " ";
}
// Print out the results of the Cruise details using the correct spacing variables
System.out.println(cruiseName + cruiseNameSpace + cruiseShipName + cruiseShipSpace + departurePort + departureSpace + destination + destinationSpace + returnPort);
}
// method added to print ship's name vice memory address
@Override
public String toString() {
return cruiseName;
}
}