Class AddFlight

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

public class AddFlight extends Object implements Command
The AddFlight class represents a command to add a new flight to the flight booking system. It implements the Command interface and requires execution within a FlightBookingSystem instance.

The flight is identified by its flight number, origin, destination, departure date, capacity, and price. Upon execution, the system assigns a unique ID to the new flight, creates a Flight object with the provided details, adds it to the system using flightBookingSystem, and stores the updated data using FlightBookingSystemData.

Example usage:


 String flightNumber = "BA123";
 String origin = "London";
 String destination = "New York";
 LocalDate departureDate = LocalDate.of(2024, 6, 1);
 int capacity = 250;
 double price = 500.00;
 Command addFlightCommand = new AddFlight(flightNumber, origin, destination, departureDate, capacity, price);
 addFlightCommand.execute(flightBookingSystem);
 
  • Constructor Details

    • AddFlight

      public AddFlight(String flightNumber, String origin, String destination, LocalDate departureDate, int capacity, double price)
      Constructs an AddFlight command with the specified flight details.
      Parameters:
      flightNumber - The flight number of the flight
      origin - The origin of the flight
      destination - The destination of the flight
      departureDate - The departure date of the flight
      capacity - The capacity of the flight (number of seats)
      price - The price of the flight
  • Method Details

    • execute

      public void execute(FlightBookingSystem flightBookingSystem) throws FlightBookingSystemException, IOException
      Executes the AddFlight command within the provided FlightBookingSystem instance. Generates a unique ID for the new flight, creates a Flight object with the provided flight details, adds it to the system using flightBookingSystem, and stores the updated data using FlightBookingSystemData.
      Specified by:
      execute in interface Command
      Parameters:
      flightBookingSystem - The FlightBookingSystem instance on which the flight is to be added
      Throws:
      FlightBookingSystemException - If there is an issue adding the flight to the system
      IOException - If there is an error storing data using FlightBookingSystemData