The answer box below includes some methods of the class FlightPlan that you should not alter, as well as the declaration
Posted: Fri Jun 10, 2022 11:58 am
The answer box below includes some methods of the class
FlightPlan that you should not alter, as well as the
declarations for the fields of the
AirTrafficControl class.
(a) Develop only the class FlightPlan in this part,
which is already partially developed below.
(i) Add a declaration for a private instance variable called
route, which should be declared as a ArrayList containing elements
of type Waypoint.
(ii) Add a public constructor for FlightPlan that takes one
string parameter representing the call sign of the airplane and
initialises the related variable accordingly. The constructor
should also initialise route to a suitable empty
collection.
(iii) Add a standard getter method for the
route collection.
(iv) Write a public instance method greatestAltitude that
has no parameters and returns the altitude of the highest waypoint
on the route of this flight plan. You can assume that there
are at least three waypoints on the route.
(v) Write a public instance method
destination that returns the name of the final waypoint
on the route of this flight plan.
(vi) The air traffic controllers want to be able to sort flight
plans by their call signs in ascending order. Modify the
FlightPlan class so that it implements the appropriate
interface, and then implement the compareTo method that will allow
the ordering required.
(b) Develop only the class AirTrafficControl in
this part, which is already partially developed below.
(i) Add a public AirTrafficControl constructor that initialises
flightPlans to a suitable collection type (initially
empty).
(ii) Add a public method addFlightPlan that adds the parameter,
of type FlightPlan to flightPlans. Nothing is returned from the
method.
(iii) Add a public instance method routeMap that returns a
HashMap in which the keys are the call signs of the flight plans
and each value is an ArrayList of the names of the waypoints on the
corresponding route, in the order in which they should be
encountered.
-------
Waypoint Class
-------
Template
//Scroll down to see the AirTrafficContol class below the
FlightPlan class
/**
* The class FlightPlan models a flight plan for an air
journey.
* Complete the class according to the instructions in part
(a)
*/
import java.util.*;
class FlightPlan
{
private String callSign;
/**
* Getter for the call sign of the aircraft
*/
public String getCallSign()
{
return callSign;
}
/**
* A simple equals method
*/
public boolean equals(Object o)
{
FlightPlan f = (FlightPlan) o;
return
getCallSign().equals(f.getCallSign());
}
/**
* return a hash code for this object based on
its call sign
*/
public int hashCode()
{
return
callSign.hashCode();
}
}
/**
* This class models Air Traffic Control that oversees flight
plans.
* Complete this class according to the instructions in part
(b)
*/
class AirTrafficControl
{
public TreeSet<FlightPlan> flightPlans;
//public for testing purposes
public TreeSet<FlightPlan>
getFlightPlans()
{
return
flightPlans;
}
// Add further code for the AirTrafficControl
class here
}
FlightPlan that you should not alter, as well as the
declarations for the fields of the
AirTrafficControl class.
(a) Develop only the class FlightPlan in this part,
which is already partially developed below.
(i) Add a declaration for a private instance variable called
route, which should be declared as a ArrayList containing elements
of type Waypoint.
(ii) Add a public constructor for FlightPlan that takes one
string parameter representing the call sign of the airplane and
initialises the related variable accordingly. The constructor
should also initialise route to a suitable empty
collection.
(iii) Add a standard getter method for the
route collection.
(iv) Write a public instance method greatestAltitude that
has no parameters and returns the altitude of the highest waypoint
on the route of this flight plan. You can assume that there
are at least three waypoints on the route.
(v) Write a public instance method
destination that returns the name of the final waypoint
on the route of this flight plan.
(vi) The air traffic controllers want to be able to sort flight
plans by their call signs in ascending order. Modify the
FlightPlan class so that it implements the appropriate
interface, and then implement the compareTo method that will allow
the ordering required.
(b) Develop only the class AirTrafficControl in
this part, which is already partially developed below.
(i) Add a public AirTrafficControl constructor that initialises
flightPlans to a suitable collection type (initially
empty).
(ii) Add a public method addFlightPlan that adds the parameter,
of type FlightPlan to flightPlans. Nothing is returned from the
method.
(iii) Add a public instance method routeMap that returns a
HashMap in which the keys are the call signs of the flight plans
and each value is an ArrayList of the names of the waypoints on the
corresponding route, in the order in which they should be
encountered.
-------
Waypoint Class
-------
Template
//Scroll down to see the AirTrafficContol class below the
FlightPlan class
/**
* The class FlightPlan models a flight plan for an air
journey.
* Complete the class according to the instructions in part
(a)
*/
import java.util.*;
class FlightPlan
{
private String callSign;
/**
* Getter for the call sign of the aircraft
*/
public String getCallSign()
{
return callSign;
}
/**
* A simple equals method
*/
public boolean equals(Object o)
{
FlightPlan f = (FlightPlan) o;
return
getCallSign().equals(f.getCallSign());
}
/**
* return a hash code for this object based on
its call sign
*/
public int hashCode()
{
return
callSign.hashCode();
}
}
/**
* This class models Air Traffic Control that oversees flight
plans.
* Complete this class according to the instructions in part
(b)
*/
class AirTrafficControl
{
public TreeSet<FlightPlan> flightPlans;
//public for testing purposes
public TreeSet<FlightPlan>
getFlightPlans()
{
return
flightPlans;
}
// Add further code for the AirTrafficControl
class here
}