-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFlightReservationSystem.java
120 lines (112 loc) · 4.91 KB
/
FlightReservationSystem.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
import java.util.ArrayList;
import java.util.PriorityQueue;
import java.util.Scanner;
// Flight System for one single day at YYZ (Print this in title) Departing flights!!
public class FlightReservationSystem {
public static void main(String[] args) {
//Creating a FlightManager object
FlightManager manager = new FlightManager();
//Creating a Reservation object arraylist
ArrayList<Reservation> myReservations = new ArrayList<Reservation>(); // my flight reservations
//Reading the inputs
Scanner scanner = new Scanner(System.in);
System.out.print(">");
while (scanner.hasNextLine()) {
String inputLine = scanner.nextLine();
if (inputLine == null || inputLine.equals("")) {
System.out.print("\n>");
continue;
}
Scanner commandLine = new Scanner(inputLine);
String action = commandLine.next();
if (action == null || action.equals("")) {
System.out.print("\n>");
continue;
}
//If QUIT is entered the program ends
else if (action.equals("Q") || action.equals("QUIT"))
return;
//Prints the list of flights that has been read from the .txt file
else if (action.equalsIgnoreCase("LIST")) {
manager.printAllFlights();
}
//Reserves the flight that has been entered according to the instructions after typing RES
else if (action.equalsIgnoreCase("RES")) {
String flightNum = null;
String passengerName = "";
String passport = "";
String seat = "";
if (commandLine.hasNext()) {
flightNum = commandLine.next();
}
if (commandLine.hasNext()) {
passengerName = commandLine.next();
}
if (commandLine.hasNext()) {
passport = commandLine.next();
}
if (commandLine.hasNext()) {
seat = commandLine.next();
Reservation res = manager.reserveSeatOnFlight(flightNum, passengerName, passport, seat);
if (res != null) {
myReservations.add(res);
res.print();
} else {
System.out.println(manager.getErrorMessage());
}
}
}
//Cancels the particular flight that has been entered as per instructions after CANCEL
else if (action.equalsIgnoreCase("CANCEL")) {
// CANCEL flight name passport
Reservation res = null;
String flightNum = null;
String passengerName = "";
String passport = "";
//String seatType = "";
if (commandLine.hasNext()) {
flightNum = commandLine.next();
}
if (commandLine.hasNext()) {
passengerName = commandLine.next();
}
if (commandLine.hasNext()) {
passport = commandLine.next();
int index = myReservations.indexOf(new Reservation(flightNum, passengerName, passport));
if (index >= 0) {
manager.cancelReservation(myReservations.get(index));
myReservations.remove(index);
} else
System.out.println("Reservation on Flight " + flightNum + " Not Found");
}
}
//Prints the seat layout as per input
else if (action.equalsIgnoreCase("SEATS")) {
String flightNum = "";
if (commandLine.hasNext()) {
flightNum = commandLine.next();
}
{
manager.flights.get(flightNum).printSeats();
}
}
//Prints the list of the passengers with details about a particular flight
else if (action.equalsIgnoreCase("PASMAN")) {
String flightNum = "";
if (commandLine.hasNext()) {
flightNum = commandLine.next();
}
manager.flights.get(flightNum).printPassengerManifest();
}
//Prints the list of flight a user has booked
else if (action.equalsIgnoreCase("MYRES")) {
for (Reservation myres : myReservations)
myres.print();
}
else if (action.equalsIgnoreCase("CRAFT")) {
manager.printAllAircraft();
}
System.out.print("\n>");
}
}
}