Class AddBooking

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

public class AddBooking extends Object implements 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

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

    Methods inherited from class java.lang.Object

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

    • AddBooking

      public AddBooking(int customerId, int outboundFlightId, LocalDate bookingDate)
      Constructs an AddBooking command with the specified customer ID, outbound flight ID, and booking date.
      Parameters:
      customerId - The ID of the customer making the booking
      outboundFlightId - The ID of the outbound flight to be booked
      bookingDate - 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 interface Command
      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 capacity
      IOException - If there is an error storing data using FlightBookingSystemData