-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtestFlightJSON.java
More file actions
210 lines (177 loc) · 6.21 KB
/
Copy pathtestFlightJSON.java
File metadata and controls
210 lines (177 loc) · 6.21 KB
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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
import java.util.ArrayList;
import java.util.Random;
import java.util.Scanner;
import java.util.UUID;
public class testFlightJSON {
private Scanner scanner;
public testFlightJSON() {
scanner = new Scanner(System.in);
}
public void playFlight() {
Flights flights = Flights.getInstance();
System.out.println("****** Current Flights *****");
displayFlights();
while(addFlight()) {
flights.addFlight(getFlight());
}
System.out.println("***** Flights Now *****");
displayFlights();
flights.logout();
}
public void playFlightGroup() {
Flights flights = Flights.getInstance();
System.out.println("****** Current Flight Groups *****");
displayFlightGroups();
while(addFlightGroup()) {
UUID flightGroupID = UUID.randomUUID();
ArrayList<Flight> allFlights = new ArrayList<>();
int numFlights = getInt("How many flights in this group?");
for (int i = 0; i < numFlights; i++) {
allFlights.add(getFlight());
}
flights.addFlightGroup(flightGroupID, allFlights);
}
System.out.println("***** Flight Groups Now *****");
displayFlightGroups();
flights.logout();
}
protected boolean addFlightGroup() {
System.out.print("Would you like to add a new flight group? (Y or N): ");
String input = scanner.nextLine();
if(input.toLowerCase().trim().equals("y")) return true;
return false;
}
protected Flight getFlight() {
UUID flightID = UUID.randomUUID();
String deptLocation = getField("Leaving From");
String arrivLocation = getField("Going to");
Plane plane = getPlane();
double price = getDouble("Price");
Reservation flightReservation = getReservation();
return new Flight(flightID, deptLocation, arrivLocation, plane, price, flightReservation);
}
protected ArrayList<Seat> chooseSeats(Flight f) {
f.getSeatChart();
System.out.println("Please choose some seats fren :):");
f.addUserSeat(getSeat());
f.addUserSeat(getSeat());
return f.getUserSeats();
}
protected boolean addFlight() {
System.out.print("Would you like to add a new flight? (Y or N): ");
String input = scanner.nextLine();
if(input.toLowerCase().trim().equals("y")) return true;
return false;
}
protected void displayFlightGroups() {
Flights flights = Flights.getInstance();
ArrayList<FlightGroup> fGroupList = flights.getFlightGroups();
for (FlightGroup fG : fGroupList) {
System.out.println(fG.toString());
}
}
protected void displayFlights() {
Flights flights = Flights.getInstance();
ArrayList<Flight> flightList = flights.getFlights();
for (Flight f: flightList) {
System.out.println(f.toString());
System.out.println(f.getSeatChart());
}
}
protected Plane getPlane() {
Airline airline = getAirline();
ArrayList<Seat> allSeats = getAllSeats();
Seat seat = getSeat();
return new Plane(airline, seat, allSeats);
}
protected ArrayList<Seat> getAllSeats() {
ArrayList<Seat> temp = new ArrayList<>();
int size = 120;
int rowCount = 0;
Random r = new Random();
for (int i = 0; i < size; i++) {
if (i%6 == 0)
rowCount++;
switch(i%6) {
case 0 :
temp.add(new Seat((rowCount + "A"), r.nextBoolean()));
break;
case 1:
temp.add(new Seat((rowCount + "B"), r.nextBoolean()));
break;
case 2:
temp.add(new Seat((rowCount + "C"), r.nextBoolean()));
break;
case 3:
temp.add(new Seat((rowCount + "D"), r.nextBoolean()));
break;
case 4:
temp.add(new Seat((rowCount + "E"), r.nextBoolean()));
break;
case 5:
temp.add(new Seat((rowCount + "F"), r.nextBoolean()));
break;
}
}
return temp;
}
protected Seat getSeat() {
String seating = getField("Seating (\"1A\"):");
// boolean available = getBool("Avalable? (T/F):");
return new Seat(seating, false);
}
protected boolean getBool(String string) {
String bool = getField(string);
return bool.trim().equalsIgnoreCase("t");
}
protected Airline getAirline() {
System.out.println("Flight Types: ");
for (int i = 0; i < Airline.values().length; i++) {
System.out.println(i + ": " + Airline.values()[i]);
}
System.out.println("Choose one: ");
int scan = scanner.nextInt();
scanner.nextLine();
switch(scan) {
case 0:
return Airline.DELTA;
case 1:
return Airline.AMERICAN;
case 2:
return Airline.UNITED;
case 3:
return Airline.SPIRIT;
case 4:
return Airline.JETBLUE;
}
return Airline.DELTA;
}
protected String getField(String prompt) {
System.out.print(prompt + ": ");
return scanner.nextLine();
}
protected int getInt(String prompt) {
System.out.print(prompt + ": ");
int temp = scanner.nextInt();
scanner.nextLine();
return temp;
}
protected double getDouble(String prompt) {
System.out.print(prompt + ": ");
double price = scanner.nextDouble();
scanner.nextLine();
return price;
}
protected Reservation getReservation() {
Date sDate = new Date(getField("Date (mm/dd/yy"));
Date eDate = new Date(getField("Date (mm/dd/yy"));
Time sTime = new Time(getField("Time (hh:mm a/pm"));
Time eTime = new Time(getField("Time (hh:mm a/pm"));
return new Reservation(sDate, eDate, sTime, eTime);
}
public static void main(String[] args) {
testFlightJSON test = new testFlightJSON();
// test.playFlightGroup();
test.playFlight();
}
}