Class AddBooking
java.lang.Object
bcu.cmp5332.bookingsystem.commands.AddBooking
- All Implemented Interfaces:
Command
The AddBooking class represents a command to add a booking to the flight booking system.
It implements the Command interface and requires execution within a FlightBookingSystem instance.
The booking is associated with a specific customer and outbound flight on a specified booking date. If the outbound flight is at full capacity, the booking cannot be issued, and an exception is thrown. Upon successful booking, the updated system data is stored using FlightBookingSystemData.
Example usage:
int customerId = 1;
int outboundFlightId = 101;
LocalDate bookingDate = LocalDate.now();
Command addBookingCommand = new AddBooking(customerId, outboundFlightId, bookingDate);
addBookingCommand.execute(flightBookingSystem);
-
Field Summary
Fields inherited from interface bcu.cmp5332.bookingsystem.commands.Command
HELP_MESSAGE
-
Constructor Summary
ConstructorDescriptionAddBooking
(int customerId, int outboundFlightId, LocalDate bookingDate) Constructs an AddBooking command with the specified customer ID, outbound flight ID, and booking date. -
Method Summary
Modifier and TypeMethodDescriptionvoid
execute
(FlightBookingSystem flightBookingSystem) Executes the AddBooking command within the provided FlightBookingSystem instance.
-
Constructor Details
-
AddBooking
Constructs an AddBooking command with the specified customer ID, outbound flight ID, and booking date.- Parameters:
customerId
- The ID of the customer making the bookingoutboundFlightId
- The ID of the outbound flight to be bookedbookingDate
- The date on which the booking is made
-
-
Method Details
-
execute
public void execute(FlightBookingSystem flightBookingSystem) throws FlightBookingSystemException, IOException Executes the AddBooking command within the provided FlightBookingSystem instance. Retrieves the customer and outbound flight based on IDs, checks if the outbound flight has capacity for additional passengers, and issues the booking if possible. If successful, the updated system data is stored using FlightBookingSystemData.- Specified by:
execute
in interfaceCommand
- Parameters:
flightBookingSystem
- The FlightBookingSystem instance on which the booking is to be added- Throws:
FlightBookingSystemException
- If the customer or flight does not exist, or if the flight is at full capacityIOException
- If there is an error storing data using FlightBookingSystemData
-