-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathUI.java
412 lines (371 loc) · 14.3 KB
/
UI.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
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
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
import java.util.Scanner;
public class UI {
private Facade facade;
private boolean quit;
private boolean quitAccount; // allows us to exit account sub menu
private int userChoice;
private Scanner kb;
private boolean loggedIn;
public UI() {
this.facade = new Facade();
this.quit = false;
this.quitAccount = false;
this.userChoice = -1;
this.kb = new Scanner(System.in);
loggedIn = false;
}
/**
* Runs the program
*/
public void run() {
do{
System.out.println("Welcome to our Flight and Hotel booking Program!\n");
while (!loggedIn) {
loggedIn = loginPrompt();
}
mainPrompt();
this.userChoice = checkValidInputInt();
mainOptionDecider(userChoice);
} while(!quit);
kb.close();
}
public static void main(String[] args) {
UI ui = new UI();
ui.run();
}
/**
* Asks for the users login information
* @return boolean
*/
public boolean loginPrompt(){
boolean loginSuccessful = false;
String tempUserInput = "";
String tempEmail = "";
String tempPassword = "";
System.out.print("Do you have an account? (Y/N): ");
tempUserInput = kb.nextLine();
if(tempUserInput.equalsIgnoreCase("y")){
System.out.print("Please enter your email: ");
tempEmail = kb.nextLine();
System.out.print("Please enter your password: ");
tempPassword = kb.nextLine();
loginSuccessful = facade.loginValidation(tempEmail, tempPassword);
// if account user is found, prompt for password and check against the stored password.
// if they match, log the user in, set return value to true, and show them the main prompt
// if they dont, then notify user and prompt again
} else if(tempUserInput.equalsIgnoreCase("n")){
while(!createAccountPrompt());
loginSuccessful = true;
}
// ending bracket of if else statement checking if user input is y or n
return loginSuccessful;
} // ending bracket of method loginPrompt
public void mainPrompt(){
System.out.println("******************* Main Menu *******************");
System.out.println("1. View Account Info\n2. Find/Book Flight\n3. Find/Book Hotel\n4. Cancel Flight\n5. Cancel Hotel\n6. Print Itinerary\n7. End Program\n");
}
/**
* Checks to see if the user input is valid
* @return
*/
public int checkValidInputInt() {
int rv = kb.nextInt();
kb.nextLine();
return rv;
} // ending bracket of method checkValidInputInt
/**
* Creates an account page for the user
* @return
*/
public boolean createAccountPrompt(){
boolean createSuccessful = false;
String tempEmail = "";
String tempPassword = "";
String name = "";
String dateOfBirth = "";
int passportNumber = -1;
System.out.println("******************* Create Account *******************");
System.out.print("Please enter your email address: ");
tempEmail = kb.nextLine();
System.out.print("Please enter your desired password: ");
tempPassword = kb.nextLine();
System.out.print("Please enter your full name: ");
name = kb.nextLine();
System.out.print("Please enter your date of birth (MM/dd/yyyy): ");
dateOfBirth = kb.nextLine();
System.out.print("Please enter your passport number: ");
passportNumber = checkValidInputInt();
createSuccessful = facade.createAccount(tempEmail, tempPassword, name, facade.dateConverter(dateOfBirth), passportNumber);
// if else statement here to notify user if their account was successfully created or not
// we could make this createAccount method return a boolean value if we want to loop them back
// through if the creation is unsuccessful. If successful, save account to json.
return createSuccessful;
} // ending bracket of createAccountPrompt
/**
* Main menu options for the user
* @param choice
*/
public void mainOptionDecider(int choice){
switch(choice){
case 1:
do {
viewAccountPrompt();
userChoice = checkValidInputInt();
viewAccountDecider(userChoice);
} while(!quitAccount);
break;
case 2:
findFlightPrompt();
break;
case 3:
findHotelPrompt();
break;
case 4:
cancelFlightPrompt();
break;
case 5:
cancelHotelPrompt();
break;
case 6:
facade.printItinerary();
break;
case 7:
quit = true;
System.out.println("Thanks for using our program!");
break;
default:
System.out.println("Option out of bounds! Choose an option 1 - 7");
break;
} // ending of switch case for mainPrompt
} // ending bracket of method mainOptionDecider
/**
* Views the account prompt
*/
public void viewAccountPrompt(){
System.out.println("******************* Account *******************");
System.out.println("1. View Booked Flights\n2. View Flight History\n3. View Booked Rooms\n4. View Hotel History\n5. Main Menu");
}
/**
* Gives options for the user
* @param choice
*/
public void viewAccountDecider(int choice){
switch(choice){
case 1:
System.out.println("******************* Booked Flights *******************");
facade.displayBookedFlights();
break;
case 2:
System.out.println("******************* Flight History *******************");
facade.displayFlightHistory();
break;
case 3:
System.out.println("******************* Booked Hotels *******************");
facade.displayBookedHotels();
break;
case 4:
System.out.println("******************* Hotel History *******************");
facade.displayHotelHistory();
break;
case 5:
quitAccount = true;
break;
default:
System.out.println("Option out of bounds! Choose an option 1 - 5");
break;
}
}// ending bracket of method viewAccountDecider
/**
* Finds the flight prompt
*/
public void findFlightPrompt(){
String startingCode = "";
String destinationCode = "";
String seatCode = "";
int flightChoiceInt = -1;
int guestAmount = 0;
boolean validFlight = false;
System.out.println("******************* Find Flight *******************");
System.out.print("Enter the Airport Code of your starting airport:");
startingCode = kb.nextLine();
System.out.print("Enter the Airport Code of your destination:");
destinationCode = kb.nextLine();
if(guestPrompt()){
System.out.print("Enter the amount of guests: ");
guestAmount = checkValidInputInt();
guestCreator(guestAmount);
} // ending bracket of if statement
facade.searchFlights(startingCode, destinationCode);
sortFlightsPrompt();
while(!validFlight){
System.out.print("\nEnter the number of the flight you want to book: ");
flightChoiceInt = checkValidInputInt();
validFlight = facade.chooseFlight(flightChoiceInt);
} // ending bracket of while loop
facade.displaySeats();
System.out.print("Enter the seat code you wish to book: ");
chooseSeatPrompt(guestAmount);
// display seats and choose for self and guests
}
/**
* Finds the prompt for hotel
*/
public void findHotelPrompt(){
String hotelLocation = "";
int hotelChoiceInt = -1;
System.out.println("******************* Find Hotel *******************");
System.out.print("\nEnter the city you wish to stay in: ");
hotelLocation = kb.nextLine();
facade.searchHotels(hotelLocation);
sortHotelsPrompt();
System.out.print("Enter the number of the hotel you wish to book: ");
hotelChoiceInt = checkValidInputInt();
facade.chooseHotel(hotelChoiceInt);
hotelDatePrompt();
}
/**
* Gives the user an option of when they will be staying
*/
public void hotelDatePrompt(){
String checkInDate = "";
String checkOutDate = "";
int tempRoomNumber = -1;
String checkInTime = "";
String checkOutTime = "";
System.out.print("What date will you check in? (MM/dd/yyyy): ");
checkInDate = kb.nextLine();
System.out.print("What time will you check in? (hh:mm): "); // will automatically add ss
checkInTime = kb.nextLine();
System.out.print("What date will you check out? (MM/dd/yyyy): ");
checkOutDate = kb.nextLine();
System.out.print("What time will you check out? (hh:mm): "); // will automatically add ss
checkOutTime = kb.nextLine();
String formattedCheckIn = checkInDate + " " + checkInTime;
String formattedCheckOut = checkOutDate + " " + checkOutTime;
System.out.println("Rooms open during your times: ");
facade.displayRooms(facade.dateAndTimeConverter(formattedCheckIn), facade.dateAndTimeConverter(formattedCheckOut));
System.out.print("\nEnter the room number you wish to stay in: ");
tempRoomNumber = checkValidInputInt();
facade.chooseHotel(tempRoomNumber);
System.out.println(tempRoomNumber + " room booked from " + checkInDate + " through " + checkOutDate);
}
/**
* Allows the user to cancel their flight
*/
public void cancelFlightPrompt(){
System.out.println("******************* Cancel Flight *******************");
facade.displayBookedFlights();
System.out.print("Enter the number of the flight you wish to cancel: ");
if(facade.deleteUserFlight(checkValidInputInt())){
System.out.println("\nFlight Successfully Cancelled");
}
}
/**
* Allows the user to cancel their hotel
*/
public void cancelHotelPrompt(){
System.out.println("******************* Cancel Hotel *******************");
facade.displayBookedHotels();
System.out.print("Enter the number of the hotel you wish to cancel: ");
if(facade.deleteUserHotel(checkValidInputInt())){
System.out.println("\nHotel Successfully Cancelled");
}
}
/**
* Allows the user to add a guest
* @return
*/
public boolean guestPrompt(){
boolean hasGuests = false;
String guestResponse = "";
System.out.println("Do you have guest you want to book for? (Y/N)");
guestResponse = kb.nextLine();
if(guestResponse.contains("y") || guestResponse.contains("Y")){
hasGuests = true;
} else if(guestResponse.contains("n") || guestResponse.contains("N")){
hasGuests = false;
} else {
hasGuests = false;
}
return hasGuests;
}
/**
* Allows the user to enter their guests information
* @param amountOfGuests
*/
public void guestCreator(int amountOfGuests){
String tempGuestName = "";
String tempDateOfBirth = "";
int tempPassportNumber = -1;
for(int i = 0; i < amountOfGuests; i++){
System.out.println("Enter the full name of guest #" + i+1 + ": ");
tempGuestName = kb.nextLine();
System.out.print("Enter their date of birth (MM/dd/yyyy): "); // maybe add valid bday format check
tempDateOfBirth = kb.nextLine();
System.out.print("Enter their passport number: ");
tempPassportNumber = checkValidInputInt();
facade.addGuest(tempGuestName, facade.dateConverter(tempDateOfBirth), tempPassportNumber);
}
}
/**
* Allows the user to choose their seat
* @param guestAmount
*/
public void chooseSeatPrompt(int guestAmount){
String userSeat = "";
String guestSeat = "";
userSeat = kb.nextLine();
facade.chooseSeat(userSeat);
for(int i = 0; i < guestAmount; i++){
System.out.print("Enter the seat code for Guest " + facade.getGuests().get(i).getName() + ": ");
guestSeat = kb.nextLine();
facade.chooseSeatForGuest(guestSeat, facade.getGuests().get(i));
// need to add passenger to seat
}
System.out.println("Seats booked. Purchase complete.");
}
/**
* Allows the user to sort the flights
*/
public void sortFlightsPrompt(){
System.out.println("Enter the way you would like to sort: ");
System.out.println("1. Name\n2. Price");
sortFlightsDecider(checkValidInputInt());
}
/**
* Allows the user to sort hotels
*/
public void sortHotelsPrompt(){
System.out.println("Enter the way you would like to sort: ");
System.out.println("1. Name\n2. Price");
sortHotelsDecider(checkValidInputInt());
}
/**
* Allows the user to choose the flight they want
* @param choice
*/
public void sortFlightsDecider(int choice){
switch(choice){
case 1:
facade.displayFlights(facade.sortFlightByName());
break;
case 2:
facade.displayFlights(facade.sortFlightByPrice());
break;
}
}
/**
* Allows the user to choose the hotel they want
* @param choice
*/
public void sortHotelsDecider(int choice){
switch(choice){
case 1:
facade.displayHotels(facade.sortHotelByName());
break;
case 2:
facade.displayHotels(facade.sortHotelByPrice());
break;
}
}
} // ending bracket of class UI