-
Notifications
You must be signed in to change notification settings - Fork 0
/
ReservationServiceImpl.java
96 lines (83 loc) · 3.7 KB
/
ReservationServiceImpl.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
import java.rmi.server.UnicastRemoteObject;
import java.rmi.RemoteException;
import java.util.ArrayList;
import java.util.List;
public class ReservationServiceImpl extends UnicastRemoteObject implements ReservationService {
private List<Flight> flightList;
private List<Fare> fareList;
private List<Reservation> reservationList;
protected ReservationServiceImpl() throws RemoteException {
super();
flightList = new ArrayList<>();
flightList.add(new Flight("69420", "Flight 1", null, null, null));
flightList.add(new Flight("54654", "Flight 2", null, null, null));
flightList.add(new Flight("86784", "Flight 3", null, null, null));
fareList = new ArrayList<>();
fareList.add(new Fare("F1", 200.0));
fareList.add(new Fare("F2", 150.0));
fareList.add(new Fare("F3", 180.0));
reservationList = new ArrayList<>();
}
//DONE. This method is used to reserve a flight
@Override
public List<Flight> consultFlights() throws RemoteException {
return flightList;
}
//DONE.
@Override
public List<Fare> consultFares(String flightId) throws RemoteException {
List<Fare> matchingFares = new ArrayList<>();
for (Fare fare : fareList) {
if (fare.getFlightId().equals(flightId)) {
matchingFares.add(fare);
}
}
return matchingFares;
}
//DONE.
@Override
public Reservation makeReservation(String flightId, String passengerName) throws RemoteException {
// TODO: Implement the reservation creation logic
Flight flight = findFlightById(flightId);
if (flight != null) {
Reservation reservation = new Reservation(passengerName, flightId, "", Reservation.ReservationType.ECONOMY, false);
reservationList.add(reservation);
return reservation;
} else {
throw new RemoteException("Flight not found.");
}
}
//-----------------------------------------------------------------------------------------------------
//solution later fuck it
//DONE BUT NO USE??
@Override
public void updatePassengerInfo(String passengerName, PassengerInfo info) throws RemoteException {
// TODO: Implement the passenger info update logic
// You may want to search for the passenger in the reservationList and update the info
}
//DONE BUT NO USE??
@Override
public void reserveFlight(Agent agent, Passenger passenger, Flight flight, String string) throws RemoteException {
// TODO: Implement the flight reservation logic
// This method takes an Agent, Passenger, and Flight as parameters; you can customize the logic accordingly
}
//-----------------------------------------------------------------------------------------------------
//DONE.
@Override
public String reserveFlight(String passengerCode, String flightCode, String seatNumber,
Reservation.ReservationType reservationType, boolean isConfirmed) throws RemoteException {
// TODO: Implement the flight reservation logic and return a confirmation message
// This method takes individual parameters for reservation; you can customize the logic accordingly
return "Reservation confirmed for passenger " + passengerCode + " on flight " + flightCode +
" with seat " + seatNumber + ". Confirmation status: " + isConfirmed;
}
// Helper method to find a flight by its ID
private Flight findFlightById(String flightId) {
for (Flight flight : flightList) {
if (flight.getCode().equals(flightId)) {
return flight;
}
}
return null;
}
}