Complete the implementations of various classes in a Flight Management System. Some example tests are given to you in the Tester class. You must implement all methods in the FlightManagementSystem by manipulating the two attributes passengers and flights, each of which declared as a HashMap.
class FlightManagementSystem f HashMap flights; HashMap passengers; /* All methods must be implemented via flights and passengers */
package fms; import java.util.ArrayList; import java.util.Arrays; import java.util.HashMap;
public double getAverageTicketAmount(Integer id) throws IdNotFoundException { }
}
-
public PassengerInfo(java.lang.String name, double TicketAmount, java.lang.Integer Id)
Parameters:
name - - name to set
TicketAmount - - TicketAmount to set
Id - - Id to set
-
-
FlightInfo
public FlightInfo(java.lang.String name, java.lang.String airline)
Parameters:
name - - flight name (e.g., SourceDestination, LondonToronto) to set
airline - - airline (e.g., AirCanada) name to set
package fms; import java.util.ArrayList;) public class FlightManagementsystem { /* * Each entry in a 'passengers' map contains * a unique ID (this is different from the flightID defined in the passenger class), and its associate HashMap
passengers; * Each entry in a 'flights' map contains * a unique id (this is different from the flightID defined in the passenger class) and its associated */ HashMap flights; /** * Initialize an empty database. public FlightManagementsystem() {|| Add a new passenger entry. * @param id - id of the passenger * @param info - information object of the passenger * @throws IdAlreadyExists Exceptoin if 'id' is an existing passenger id public void addPassenger (String id, PassengerInfo info) throws IdAlreadyExistsExceptoin { * Remove an existing passenger entry. * @param id - id of the passenger * @throws IdNotFoundException if 'id' is not an existing passenger id */ public void removePassenger (String id) throws IdNotFoundException { /** * Add a new flight entry. * @param id id of the flight * @param info information object of the flight * @throws IdAlreadyExists Exceptoin if 'id' is an existing flight id */ public void addFlight(Integer id, FlightInfo info) throws IdAlreadyExistsExceptoin { /** * Remove an existing flight entry. * @param id id of some flight * @throws IdNotFoundException if 'id' is not an existing flight * public void removeFlight(Integer id) throws IdNotFoundException * Change the flight of passenger with id 'eid' to a new flight with id 'did'. You can assume that did' denotes a flight different from the current flight of the passenger denoted by 'eid'. * @param eid id of some passenger * @param did id of some flight * @throws IdNotFoundException if either eid is a non-existing passenger id or did is a non-existing flight public void changeFlight(String eid, Integer did) throws IdNotFoundException { /** * Retrieve the name of passenger with id 'id'. * @param id id of some passenger * @return name of the passenger with id 'id' * @throws IdNotFoundException if 'id' is not an existing passenger id public String getPassengerName(String id) throws IdNotFoundException { /** * Retrieve the names of all passengers of the flight with id 'id'. * If 'id' a non-existing flight id, then return an empty list. * @param id id of some flight * @return List of names of passengers whose flight has id 'id' public ArrayList getPassengerNames (Integer id) { /** * Retrieve passengers flight information object. * @param id id of some passenger * @return The information object of the passengers flight * @throws IdNotFoundException if 'id' is not an existing passenger id public FlightInfo getFlightInfo(String id) throws IdNotFoundException { /** * Retrieve a list, sorted in increasing order, * the information objects of all stored passengers. * Hints: * 1. Override the compareTo' method in Passenger Info class. * 2. Look up the Arrays.sort method in Java API. * @return A sorted list of information objects of all passengers. public PassengerInfo[] getSortedPassengerInfo() { /** * Retrieve the average ticket paid by all passengers in flight with id 'id'. * @param id id of some flight * @return average ticket paid by all passengers in a flight with id 'id' * @throws IdNotFoundException if id is not an existing flight id package fms; import java.util.ArrayList;) public class FlightManagementsystem { /* * Each entry in a 'passengers' map contains * a unique ID (this is different from the flightID defined in the passenger class), and its associate HashMap passengers; * Each entry in a 'flights' map contains * a unique id (this is different from the flightID defined in the passenger class) and its associated */ HashMap flights; /** * Initialize an empty database. public FlightManagementsystem() {|| Add a new passenger entry. * @param id - id of the passenger * @param info - information object of the passenger * @throws IdAlreadyExists Exceptoin if 'id' is an existing passenger id public void addPassenger (String id, PassengerInfo info) throws IdAlreadyExistsExceptoin { * Remove an existing passenger entry. * @param id - id of the passenger * @throws IdNotFoundException if 'id' is not an existing passenger id */ public void removePassenger (String id) throws IdNotFoundException { /** * Add a new flight entry. * @param id id of the flight * @param info information object of the flight * @throws IdAlreadyExists Exceptoin if 'id' is an existing flight id */ public void addFlight(Integer id, FlightInfo info) throws IdAlreadyExistsExceptoin { /** * Remove an existing flight entry. * @param id id of some flight * @throws IdNotFoundException if 'id' is not an existing flight * public void removeFlight(Integer id) throws IdNotFoundException * Change the flight of passenger with id 'eid' to a new flight with id 'did'. You can assume that did' denotes a flight different from the current flight of the passenger denoted by 'eid'. * @param eid id of some passenger * @param did id of some flight * @throws IdNotFoundException if either eid is a non-existing passenger id or did is a non-existing flight public void changeFlight(String eid, Integer did) throws IdNotFoundException { /** * Retrieve the name of passenger with id 'id'. * @param id id of some passenger * @return name of the passenger with id 'id' * @throws IdNotFoundException if 'id' is not an existing passenger id public String getPassengerName(String id) throws IdNotFoundException { /** * Retrieve the names of all passengers of the flight with id 'id'. * If 'id' a non-existing flight id, then return an empty list. * @param id id of some flight * @return List of names of passengers whose flight has id 'id' public ArrayList getPassengerNames (Integer id) { /** * Retrieve passengers flight information object. * @param id id of some passenger * @return The information object of the passengers flight * @throws IdNotFoundException if 'id' is not an existing passenger id public FlightInfo getFlightInfo(String id) throws IdNotFoundException { /** * Retrieve a list, sorted in increasing order, * the information objects of all stored passengers. * Hints: * 1. Override the compareTo' method in Passenger Info class. * 2. Look up the Arrays.sort method in Java API. * @return A sorted list of information objects of all passengers. public PassengerInfo[] getSortedPassengerInfo() { /** * Retrieve the average ticket paid by all passengers in flight with id 'id'. * @param id id of some flight * @return average ticket paid by all passengers in a flight with id 'id' * @throws IdNotFoundException if id is not an existing flight id