Complete the implementations of various classes in a Flight
Management, 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
for flight name and airline name, respectively ) can be uniquely
identified by an integer id. 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<Integer, FlightInfo> flights;
HashMap<String, PassengerInfo > 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
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<String, PassengerInfo> 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<Integer, FlightInfo> 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<String>
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 {
}
}
Returns:
average ticket paid by all passengers in a flight with id 'id'
Throws:
IdNotFoundException - if id is not an existing flight id
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
class PassengerInfo implements Comparable<PassengerInfo>
{
private String name;
private double ticketAmount;
private int id;
public PassengerInfo(String name, double
ticketAmount, int id) {
this.name =
name;
this.ticketAmount =
ticketAmount;
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name =
name;
}
public double getTicketAmount() {
return
ticketAmount;
}
public void setTicketAmount(double
ticketAmount) {
this.ticketAmount =
ticketAmount;
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
@Override
public int compareTo(PassengerInfo o)
{
if(ticketAmount
< o.ticketAmount) {
return
-1;
} else
if(ticketAmount > o.ticketAmount) {
return
1;
} else {
return
o.id - id;
}
}
@Override
public boolean equals(Object obj) {
if (this ==
obj)
return
true;
if (obj ==
null)
return
false;
if (getClass() !=
obj.getClass())
return
false;
PassengerInfo other
= (PassengerInfo) obj;
if (id !=
other.id)
return
false;
if (name == null)
{
if
(other.name != null)
return
false;
} else if
(!name.equals(other.name))
return
false;
if
(Double.doubleToLongBits(ticketAmount) !=
Double.doubleToLongBits(other.ticketAmount))
return
false;
return true;
}
}
class FlightInfo {
private String name, airline;
public FlightInfo(String name, String
airline) {
this.name =
name;
this.airline =
airline;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name =
name;
}
public String getAirline() {
return
airline;
}
public void setAirline(String airline)
{
this.airline =
airline;
}
@Override
public boolean equals(Object obj) {
if (this ==
obj)
return
true;
if (obj ==
null)
return
false;
if (getClass() !=
obj.getClass())
return
false;
FlightInfo other =
(FlightInfo) obj;
if (airline ==
null) {
if
(other.airline != null)
return
false;
} else if
(!airline.equals(other.airline))
return
false;
if (name == null)
{
if
(other.name != null)
return
false;
} else if
(!name.equals(other.name))
return
false;
return true;
}
}
class IdAlreadyExistsExceptoin extends Exception {
}
class IdNotFoundException extends Exception {
}
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<String, PassengerInfo>
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<Integer, FlightInfo>
flights;
/**
* Initialize an empty database.
*/
public FlightManagementSystem() {
passengers = new
HashMap<>();
flights = new
HashMap<>();
}
/**
* 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 {
if(passengers.containsKey(id))
{
throw
new IdAlreadyExistsExceptoin();
}
passengers.put(id,
info);
}
/**
* 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 {
if(!passengers.containsKey(id))
{
throw
new IdNotFoundException();
}
passengers.remove(id);
}
/**
* 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 {
if(flights.containsKey(id))
{
throw
new IdAlreadyExistsExceptoin();
}
flights.put(id,
info);
}
/**
* 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 {
if(!flights.containsKey(id))
{
throw
new IdNotFoundException();
}
flights.remove(id);
}
/**
* 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 {
if(!passengers.containsKey(eid))
{
throw
new IdNotFoundException();
}
passengers.get(eid).setId(did);
}
/**
* 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 {
if(!passengers.containsKey(id))
{
throw
new IdNotFoundException();
}
return
passengers.get(id).getName();
}
/**
* 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<String>
getPassengerNames(Integer id) {
ArrayList<String>
result = new ArrayList<>();
for(PassengerInfo
p: passengers.values()) {
if(p.getId()
== id) {
result.add(p.getName());
}
}
return
result;
}
/**
* 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 {
if(!passengers.containsKey(id))
{
throw
new IdNotFoundException();
}
return
flights.get(passengers.get(id).getId());
}
/**
* 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() {
ArrayList<PassengerInfo>
p = new ArrayList<>();
p.addAll(passengers.values());
Collections.sort(p);
PassengerInfo
result[] = new PassengerInfo[p.size()];
return
p.toArray(result);
}
/**
* 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
{
double total =
0;
for(PassengerInfo
p: passengers.values()) {
total
+= p.getTicketAmount();
}
return
total/passengers.size();
}
}
************************************************** Thanks for your question. We try our best to help you with detailed answers, But in any case, if you need any modification or have a query/issue with respect to above answer, Please ask that in the comment section. We will surely try to address your query ASAP and resolve the issue.
Please consider providing a thumbs up to this question if it helps you. by Doing that, You will help other students, who are facing similar issue.
Complete the implementations of various classes in a Flight Management, We consider a database that stores...
How to complete this methods: import java.io.FileInputStream; import java.io.FileNotFoundException; import java.time.LocalDate; import java.util.ArrayList; import java.util.HashMap; import java.util.HashSet; import java.util.List; import java.util.Scanner; import java.util.Set; /** * Utility class that deals with all the other classes. * * @author EECS2030 Summer 2019 * */ public final class Registrar { public static final String COURSES_FILE = "Courses.csv"; public static final String STUDENTS_FILE = "Students.csv"; public static final String PATH = System.getProperty("java.class.path"); /** * Hash table to store the list of students using their...
How to complete these methods: /** * Returns a reference to the course with title equals to the argument. This * method searches in the courses stored in the HashMap {@code courses} to find * the course whose title equals to the argument {@code title}. If the course is * not found, {@code null} is returned. * * @param title the title of the course * @return a reference to the course, or {@code null} if the course is not ...
JAVA ONLY Design two classes: Flight and Itinerary. The Flight class stores the information about a flight with the following members: 1. A data field named flightNo of the String type with getter method. 2. A data field named departureTime of the GregorianCalendar type with getter and setter methods. 3. A data field named arrivalTime of the GregorianCalendar type with getter and setter methods. 4. A constructor that creates a Flight with the specified number, departureTime, and arrivalTime. 5. A...
Problem 1 Consider the following relations containing airline flight information, where the keys are underlined ghts(no: integer, from: string, to: string, distance: integer, departs: time, arrives: time) aircraftlaid: integer, aname: string, crusingrange: integer) certified(eid: integer,aid: integer) employees(eid: integer, ename: string, salary: integer) Note that the employees relation describes pilots and other kinds of employees as well; every pilot is certified for some aircraft (otherwise, he or she would not qualify as a pilot), and only pilots are certified to fly....
Complete the implementation of the LinkedStack class presented in Chapter 13. Specifically, complete the implementations of the peek, isEmpty, size, and toString methods. See Base_A06Q1.java for a starting place and a description of these methods. Here is the base given: /** * Write a description of the program here. * * @author Lewis et al., (your name) * @version (program version) */ import java.util.Iterator; public class Base_A06Q1 { /** * Program entry point for stack testing. * @param args Argument...
Can anyone identify which OO Design Patterns are being used in the following code?: package mis; import java.util.ArrayList; import java.util.HashMap; import java.util.Iterator; import java.util.Map; import java.util.Map.Entry; import java.util.Scanner; class helpDeskGuidline{ private void setGuideLine(){ } public void rateService(){ } } public class HelpDeskService extends helpDeskGuidline{ //HelpDeskService class extends helpDeskGuidline this //called inheritance private static int ticketId=1; Ticket ticket; // HelpDeskService class using ticket class object. this is has-A relationship (aggregation) ArrayList<Ticket> allTicket=new ArrayList<>(); HashMap<Ticket,Person> ticketAllocation=new HashMap<>(); HashMap<Person,Integer> assignee=new HashMap<>(); HelpDeskService(){ Person...
Lab Assignment : In this lab, you are going to implement QueueADT interface that defines a queue. Then you are going to use the queue to store animals. 1. Write a LinkedQueue class that implements the QueueADT.java interface using links. 2. Textbook implementation uses a count variable to keep track of the elements in the queue. Don't use variable count in your implementation (points will be deducted if you use instance variable count). You may use a local integer variable...
I need help with my homework. The task: Actually, you find flying very good, but you do not trust the whole new-fangled flying stuff and the infrastructure it has built up. As a diehard medieval metal fan you prefer to travel from A to B but rather the good old catapult. Since one can not easily take the favorite cat on vacation with it (cats do not get drafts, which is why ICEs are also eliminated), they let themselves be...
In this assignment, we will be making a program that reads in customers' information, and create a movie theatre seating with a number of rows and columns specified by a user. Then it will attempt to assign each customer to a seat in a movie theatre. 1. First, you need to add one additional constructor method into Customer.java file. Method Description of the Method public Customer (String customerInfo) Constructs a Customer object using the string containing customer's info. Use the...
In this problem, you will complete several classes involving boxes, locks, keys and secrets. Follow the specifications in the starter files for the classes. You can run the javadoc program to generate the API (see Tutorial 2) for the classes. A box has a secret inside it (and maybe a key!) and can be locked. In order to open a box, you need the right key to unlock the lock. Secrets.java will be a program that takes an array of...