Class AddFlight
java.lang.Object
bcu.cmp5332.bookingsystem.commands.AddFlight
- All Implemented Interfaces:
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);
-
Field Summary
Fields inherited from interface bcu.cmp5332.bookingsystem.commands.Command
HELP_MESSAGE
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
execute
(FlightBookingSystem flightBookingSystem) Executes the AddFlight command within the provided FlightBookingSystem instance.
-
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 flightorigin
- The origin of the flightdestination
- The destination of the flightdepartureDate
- The departure date of the flightcapacity
- 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 interfaceCommand
- 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 systemIOException
- If there is an error storing data using FlightBookingSystemData
-