-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBookingApp.java
More file actions
167 lines (151 loc) · 5.27 KB
/
Copy pathBookingApp.java
File metadata and controls
167 lines (151 loc) · 5.27 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
import java.util.ArrayList;
// import java.util.UUID;
/**
* The Booking App
*
*/
public class BookingApp {
private static BookingApp bookingApp = null;
private Flights flights;
private Hotels hotels;
private Cars cars;
private Users users;
private RegisteredUser mainUser;
/**
* Gets the classes instances and sets them to the classes
*/
private BookingApp() {
flights = Flights.getInstance();
hotels = Hotels.getInstance();
cars = Cars.getInstance();
users = Users.getInstance();
mainUser = new RegisteredUser();
}
/**
* Checks for the Booking App
* @return booking app
*/
public static BookingApp getInstance() {
if(bookingApp == null) {
bookingApp = new BookingApp();
}
return bookingApp;
}
/**
* Get the login details
* @param String username and password associated with the user
* @return boolean
*/
public boolean tryLogin(String username, String password) {
for (RegisteredUser u : users.getRegisteredUsers()) {
if(u.tryLogin(username, password)) {
mainUser = u;
return true;
}
}
return false;
}
/*----------------------------------------Flight Methods--------------------------------------*/
/**
* Find Flights or FlightGroups that match the user's needs
* @param deptAirportCode the IATA code for the airport the user will leave from
* @param arrivAirportCode the IATA code for the airport the user will arrive at
* @param deptDate the Date the user will leave
* @return An ArrayList<Object> filled with all Flights and FlightGroups that match and a
* String representing the Object type for each item ('f' for Flight, 'G' for FlightGroup)
*/
public Flight getFlight(Flight flight) {
return flights.getFlightByUUID(flight.getFlightID());
}
public FlightGroup getFGroup(FlightGroup fGroup) {
return flights.getFlightGroupByUUID(fGroup.getFlightGroupID());
}
public ArrayList<Object> searchForAOneWayFlight(String deptAirportCode, String arrivAirportCode, Date deptDate) {
String fOrFG = "";
ArrayList<Flight> allDirectFlights = flights.searchForDirectFlights(deptAirportCode, arrivAirportCode, deptDate);
ArrayList<FlightGroup> allOtherFlights = flights.searchForOtherFlights(deptAirportCode, arrivAirportCode, deptDate);
ArrayList<Object> allFlights = new ArrayList<>();
for (Flight f : allDirectFlights) {
allFlights.add(f);
fOrFG += "f";
}
for (FlightGroup fG : allOtherFlights) {
allFlights.add(fG);
fOrFG += "G";
}
allFlights.add(fOrFG);
return allFlights;
}
/**
* Print all of the User's saved Flights and/or FlightGroups
*/
public void printUserBookings() {
mainUser.printFlights();
}
/**
* Add a flight to the user's BookingList
* @param userFlight the flight the user has chosen
*/
public void addUserFlight(Flight userFlight) {
mainUser.addFlight(userFlight);
}
/**
* Add a FlightGroup to the user's BookingList
* @param userFG the FlightGroup the user has chosen
*/
public void addUserFGroup(FlightGroup userFG) {
mainUser.addFlightGroup(userFG);
}
/**
* Get the total number of travelers the user will need to choose seats for
* @return the number of partymembers plus the user
*/
public int getTotalTravelers() {
return mainUser.getTotalTravelers();
}
/**
* Add a PartyMember to the user's list
* @param partyMember the PartyMember to be added
*/
public void addPartyMember(PartyMember partyMember) {
mainUser.addPartyMember(partyMember);
}
/**
* Clear the user's list of PartyMembers for a new Search
*/
public void prepPartyMembers() {
mainUser.setPartyMembers(new ArrayList<>());
}
/**
* Update the flight's seatchart with the user's choice of seat
* @param flightID the ID for the flight needed to be updated
* @param userSeat the user's seat choice
*/
public void updateFlightChart(Flight flight, Seat userSeat) {
flights.updateFlightChart(flight, userSeat);
}
/*--------------------------------------------------------------------------------------------*/
/*----------------------------------------Hotel Methods--------------------------------------*/
public ArrayList<Object> searchForHotel(String address, int rating, int price,
ArrayList<String> hotelAmenities, ArrayList<String> roomAmenities) {
String fOrFG = "";
ArrayList<Hotel> allHotels = hotels.searchForHotel(address, rating, price, hotelAmenities, roomAmenities);
ArrayList<Object> allHotelsOther = new ArrayList<>();
for (Hotel h : allHotels) {
allHotelsOther.add(h);
fOrFG += "h";
}
allHotelsOther.add(fOrFG);
return allHotelsOther;
}
/*--------------------------------------------------------------------------------------------*/
/**
* Shut it down
*/
public void logout() {
flights.logout();
hotels.logout();
cars.logout();
users.logout();
}
}