Class UpdateBooking
java.lang.Object
bcu.cmp5332.bookingsystem.commands.UpdateBooking
- All Implemented Interfaces:
Command
The UpdateBooking class represents a command to update an existing booking's flight number
and booking date within a Flight Booking System.
It implements the Command interface, allowing it to be executed within the context of a FlightBookingSystem instance.
Upon execution, the command retrieves the booking identified by bookingID from the provided FlightBookingSystem instance using getBookingByID() method. If the booking does not exist, it throws a FlightBookingSystemException.
If the booking exists, it updates the booking's flight number and booking date to the new values specified during object construction.
Example usage:
// Create a new UpdateBooking command instance
Command updateBookingCommand = new UpdateBooking(bookingID, newFlightNumber, newBookDate);
// Execute the command within a FlightBookingSystem instance
updateBookingCommand.execute(flightBookingSystem);
-
Field Summary
Fields inherited from interface bcu.cmp5332.bookingsystem.commands.Command
HELP_MESSAGE
-
Constructor Summary
ConstructorDescriptionUpdateBooking
(int bookingID, String newFlightNumber, LocalDate newBookDate) Constructs an UpdateBooking command with the specified booking ID, new flight number, and new booking date. -
Method Summary
Modifier and TypeMethodDescriptionvoid
execute
(FlightBookingSystem flightBookingSystem) Executes the update booking command within the provided FlightBookingSystem instance.
-
Constructor Details
-
UpdateBooking
Constructs an UpdateBooking command with the specified booking ID, new flight number, and new booking date.- Parameters:
bookingID
- The ID of the booking to updatenewFlightNumber
- The new flight number for the bookingnewBookDate
- The new booking date for the booking
-
-
Method Details
-
execute
Executes the update booking command within the provided FlightBookingSystem instance. Retrieves the booking by its ID, updates its flight number and booking date to the new values, and throws an exception if the booking is not found.- Specified by:
execute
in interfaceCommand
- Parameters:
flightBookingSystem
- The FlightBookingSystem instance on which the command is executed- Throws:
FlightBookingSystemException
- If the booking with the specified ID is not found
-