Class UpdateBooking

java.lang.Object
bcu.cmp5332.bookingsystem.commands.UpdateBooking
All Implemented Interfaces:
Command

public class UpdateBooking extends Object implements 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);
 
See Also:
  • Field Summary

    Fields inherited from interface bcu.cmp5332.bookingsystem.commands.Command

    HELP_MESSAGE
  • Constructor Summary

    Constructors
    Constructor
    Description
    UpdateBooking(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 Type
    Method
    Description
    void
    execute(FlightBookingSystem flightBookingSystem)
    Executes the update booking command within the provided FlightBookingSystem instance.

    Methods inherited from class java.lang.Object

    equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • UpdateBooking

      public UpdateBooking(int bookingID, String newFlightNumber, LocalDate newBookDate)
      Constructs an UpdateBooking command with the specified booking ID, new flight number, and new booking date.
      Parameters:
      bookingID - The ID of the booking to update
      newFlightNumber - The new flight number for the booking
      newBookDate - The new booking date for the booking
  • Method Details

    • execute

      public void execute(FlightBookingSystem flightBookingSystem) throws FlightBookingSystemException
      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 interface Command
      Parameters:
      flightBookingSystem - The FlightBookingSystem instance on which the command is executed
      Throws:
      FlightBookingSystemException - If the booking with the specified ID is not found