Question: Complete the implementations of various classes in a Flight Management System. Read the API for FlightManagementSystem carefully, the API of this lab is available under

Complete the implementations of various classes in a Flight Management System. Read the API for FlightManagementSystem carefully, the API of this lab is available under doc folder in the Java project folder (docindex.html). Some example tests are given to you in the Tester class. You are required to write (at least three) additional tests to further ensure the correctness of your Flight Management implementations. We consider a database that stores information about passengers and flights. Each passenger record (e.g., String name, double TicketAmount, int flightID) can be uniquely identified by a String ID (e.g., e1), whereas each flight record (e.g., String airline and String flight 2 for flight name and airline name, respectively ) can be uniquely identified by an integer id (e.g., 2000). 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 { HashMap flights; HashMap passengers; /* All methods must be implemented via flights and passengers */ } Override the compareTo and equal methods in the PassengerInfo class. Override the equals method in the FlightInfo class.For simplicity, you can assume that a passenger cannot be added in multiple flights. For this question, you are required to submit Java files such as FlightInfo, PassengerInfo, FlightManagementSystem, Tester in your Eclipse project. Note that the exception classes are available in the project folder.

TESTER CLASS

package fms;

import static org.junit.Assert.*;

import java.util.ArrayList;

import org.junit.Before; import org.junit.Test;

public class Tester {

FlightManagementSystem db; /* * This method is executed before each test method is executed. */ @Before public void setUp() { db = new FlightManagementSystem(); } private void addPassengers() { try { db.addPassenger("e1", new PassengerInfo("Heeyeon" , 10, 2000)); db.addPassenger("e2", new PassengerInfo("Jiyoon" , 50, 2577)); db.addPassenger("e3", new PassengerInfo("Jaebin" , 70, 2000)); db.addPassenger("e4", new PassengerInfo("Suyeon" , 70, 2577)); db.addPassenger("e5", new PassengerInfo("Yuna" , 50, 990)); db.addPassenger("e6", new PassengerInfo("Sunhye" , 30, 2577)); db.addPassenger("e7", new PassengerInfo("Jihye" , 70, 990)); } catch (IdAlreadyExistsExceptoin e) { // exception not expected fail(); } } private void addFlights() { try { db.addFlight(2000, new FlightInfo("LondonToronto" , "AirCanada")); db.addFlight(2577, new FlightInfo("ParisLondon" , "AirFrance")); db.addFlight(990, new FlightInfo("ParisToronto" , "UnitedAirlines")); } catch (IdAlreadyExistsExceptoin e) { // exception not expected fail(); } }

FLIGHT MANAGEMENT CLASS

package fms; import java.util.ArrayList; import java.util.Arrays; import java.util.HashMap;

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 associated information object. */ 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 information object. */ 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 IdAlreadyExistsExceptoin 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 IdAlreadyExistsExceptoin 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 id. */ 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 PassengerInfo 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 */ public double getAverageTicketAmount(Integer id) throws IdNotFoundException { }

}

EXCEPTION CLASS 1

package fms;

public class IdAlreadyExistsExceptoin extends Exception { public IdAlreadyExistsExceptoin(String s) { super(s); } }

EXCEPTION CLASS 2

package fms;

public class IdNotFoundException extends Exception { public IdNotFoundException(String s) { super(s); } }

Complete the implementations of various classes in a Flight Management System. Readthe API for FlightManagementSystem carefully, the API of this lab is availableunder doc folder in the Java project folder (docindex.html). Some example testsare given to you in the Tester class. You are required to

fms Class FlightInfo java.lang. Object fms. FlightInfo public class Flight Info extends java.lang.Object Constructor Summary Constructors Constructor and Description FlightInfo(java.lang.String name, java.lang.String airline) Method Summary All Methods Instance Methods Concrete Methods Modifier and Type Method and Description boolean equals(java.lang.Object obj) Two Flight objects are equal if their name and airline are equal. java.lang.String java.lang.String void getairline() getName() setairline (java.lang.String airline) setName( java.lang.String nane) void Methods inherited from class java.lang.Object getClass, hashCode, notify, notifyAll, tostring, wait, wait, wait Constructor Detail Filghtinfo public FlightInfo(java.lang.String nane, java.lang.String airline) Parameters: name - - flight name (e.g., SourceDestination, London Toronto) to set airline -- airline (e.g., AirCanada) name to set Method Detail getName public java.lang.String getName() Returne: name - flight name to get setName public void setName( java.lang.String name) Parameters: name - - flight name to set Method Detail getName public java.lang.String getName() Returne: name - flight name to get BetName public void setNane(java.lang.String name) Parameters: name - - flight name to set getalline public java.lang.String getairline) Returns: airline-name of airline Betalline public void setairline(java.lang.String airline) Parameters: airline - - airline name to set equale public boolean equals(java.lang.Object obj) Two Flight objects are equal if their name and airline are equal. Overridea: equals in class java.lang.Object Returne: Whether the two flights are equal Class Passengerinfo java.lang. Object fms. Passengerinfo All Implemented Interfaces: java.lang.Comparable public class Passenger Info extends java.lang.Object implements java.lang.Comparable Constructor Summary Constructors Constructor and Description PassengerInfo(java.lang.String nane, double Ticket Amount, java.lang. Integer FlightId) Method Summary Concrete Methods All Methods Instance Methods Modifier and Type Method and Description int compareTo(PassengerInfo other) Compare this PassengerInfo object and other Passengerinfo object. boolean java.lang. Integer java.lang.String equals(java.lang.Object obj) Two Passengerinfo objects are equal if their name, TicketAmount, and id are equal. getFlightId() getName() getTicketAmount() setFlightId(java.lang. Integer FlightId) setName (java.lang.String nane) setTicketAmount (double Ticket Amount) double void void void Methods inherited from class java.lang.Object getClass, hashCode, notify, notifyAll, tostring, wait, wait, wait Constructor Detail Passengerinfo public PassengerInfo(java.lang.String name, double Ticket Amount, java.lang. Integer FlightId) Parameters: name -- nane to set TicketAmount - - TicketAmount to set FlightId - - Flight Id to set Method Detail getName public java.lang.String getName() Returns: the name aetName Method Detail getName public java.lang.String getName() Returns: the name aetName public void setName( java.lang.String name) Parameters: name - the name to set getTicketAmount public double getTicketAmount() Returne: TicketAmount setTicketAmount public void setTicket Amount(double TicketAmount) Parameters: TicketAmount - the Ticket Amount to set getFlightid public java.lang. Integer getFlightId() Returne: FlightId setFulghtid public void setFlightId(java.lang. Integer FlightId) Parameters: FlightId -- Flight Id to set compare To public int compareTo(Passenger Info other) Compare this Passengerinfo object and other PassengerInfo object. An Passengerinfo infoi is "smaller than another infoz if infoi's TicketAmount is smaller than infoz's. If both have the same TicketAmount, then one with a larger id is considered as "smaller". When being sorted in an increasing order (using Arrays.sort), the smaller Passengerinfo object appears earlier than the larger one. Specified by compareto in interface java.lang.Comparable Returne: Positive value if this is larger than other, negative if this is smaller than other, zero otherwise. equale public boolean equals(java.lang.Object obj) Two Passengerinfo objects are equal if their name, TicketAmount, and id are equal. Overridee: equals in class java.lang.Object Returne: Whether this Passenger Info object equals 'obj' fms Class FlightInfo java.lang. Object fms. FlightInfo public class Flight Info extends java.lang.Object Constructor Summary Constructors Constructor and Description FlightInfo(java.lang.String name, java.lang.String airline) Method Summary All Methods Instance Methods Concrete Methods Modifier and Type Method and Description boolean equals(java.lang.Object obj) Two Flight objects are equal if their name and airline are equal. java.lang.String java.lang.String void getairline() getName() setairline (java.lang.String airline) setName( java.lang.String nane) void Methods inherited from class java.lang.Object getClass, hashCode, notify, notifyAll, tostring, wait, wait, wait Constructor Detail Filghtinfo public FlightInfo(java.lang.String nane, java.lang.String airline) Parameters: name - - flight name (e.g., SourceDestination, London Toronto) to set airline -- airline (e.g., AirCanada) name to set Method Detail getName public java.lang.String getName() Returne: name - flight name to get setName public void setName( java.lang.String name) Parameters: name - - flight name to set Method Detail getName public java.lang.String getName() Returne: name - flight name to get BetName public void setNane(java.lang.String name) Parameters: name - - flight name to set getalline public java.lang.String getairline) Returns: airline-name of airline Betalline public void setairline(java.lang.String airline) Parameters: airline - - airline name to set equale public boolean equals(java.lang.Object obj) Two Flight objects are equal if their name and airline are equal. Overridea: equals in class java.lang.Object Returne: Whether the two flights are equal Class Passengerinfo java.lang. Object fms. Passengerinfo All Implemented Interfaces: java.lang.Comparable public class Passenger Info extends java.lang.Object implements java.lang.Comparable Constructor Summary Constructors Constructor and Description PassengerInfo(java.lang.String nane, double Ticket Amount, java.lang. Integer FlightId) Method Summary Concrete Methods All Methods Instance Methods Modifier and Type Method and Description int compareTo(PassengerInfo other) Compare this PassengerInfo object and other Passengerinfo object. boolean java.lang. Integer java.lang.String equals(java.lang.Object obj) Two Passengerinfo objects are equal if their name, TicketAmount, and id are equal. getFlightId() getName() getTicketAmount() setFlightId(java.lang. Integer FlightId) setName (java.lang.String nane) setTicketAmount (double Ticket Amount) double void void void Methods inherited from class java.lang.Object getClass, hashCode, notify, notifyAll, tostring, wait, wait, wait Constructor Detail Passengerinfo public PassengerInfo(java.lang.String name, double Ticket Amount, java.lang. Integer FlightId) Parameters: name -- nane to set TicketAmount - - TicketAmount to set FlightId - - Flight Id to set Method Detail getName public java.lang.String getName() Returns: the name aetName Method Detail getName public java.lang.String getName() Returns: the name aetName public void setName( java.lang.String name) Parameters: name - the name to set getTicketAmount public double getTicketAmount() Returne: TicketAmount setTicketAmount public void setTicket Amount(double TicketAmount) Parameters: TicketAmount - the Ticket Amount to set getFlightid public java.lang. Integer getFlightId() Returne: FlightId setFulghtid public void setFlightId(java.lang. Integer FlightId) Parameters: FlightId -- Flight Id to set compare To public int compareTo(Passenger Info other) Compare this Passengerinfo object and other PassengerInfo object. An Passengerinfo infoi is "smaller than another infoz if infoi's TicketAmount is smaller than infoz's. If both have the same TicketAmount, then one with a larger id is considered as "smaller". When being sorted in an increasing order (using Arrays.sort), the smaller Passengerinfo object appears earlier than the larger one. Specified by compareto in interface java.lang.Comparable Returne: Positive value if this is larger than other, negative if this is smaller than other, zero otherwise. equale public boolean equals(java.lang.Object obj) Two Passengerinfo objects are equal if their name, TicketAmount, and id are equal. Overridee: equals in class java.lang.Object Returne: Whether this Passenger Info object equals 'obj

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!