Answered You can hire a professional tutor to get the answer.

QUESTION

JAVA Create an Itinerary class. This class will represent a travel itinerary containing one or two flights in our system.

JAVA

Create an Itinerary class. This class will represent a travel itinerary containing one or two flights in our system. It should contain two constructors, two instance variables (two different Flights) and seven methods (getFirstFlight, getSecondFlight, hasConnection, getTotalCost, getDeparture, getArrival, toString) [15 points]

overloaded constructor: will take one Flight object and use it to set up the instance variables. The second Flight variable should be set to null.

overloaded constructor: will take two Flight objects and use them to set up the instance variables.

getFirstFlight(): returns the first Flight in the itinerary.

getSecondFlight(): returns the second Flight in the itinerary.

hasConnection(): returns true if the itinerary contains two Flight objects.

getTotalCost(): returns the total cost of all Flights in the itinerary.

getDeparture(): returns the departure time of the first flight in the itinerary.

getArrival(): returns the arrival time of the last flight in the itinerary.

toString(): will return the total cost of the itinerary and the "detailed string" for the Flight or Flights in the itinerary.

Create a FlightManager class. This class will store instances of the Flight class, and support generating a list of potential itineraries. It should contain one constructor, two instance variables (an array of Flights, and something that counts the number of flights in the system), and four methods (addFlight, increaseSize, findItineraries, shrinkItineraries). [25 points]

default constructor: will set up the instances variables with zero flights.

addFlight(...): Adds a flight to the flights array. Uses the increaseSize() method if the array is full.

increaseSize(): Doubles the size of the flights array, while keeping whatever is already there. Make this a private method.

findItineraries(...): Searches the flights based on source airport, destination airport, and departure time, to find 1-flight and 2-flight itineraries meeting those criteria. When searching for 2-flight itineraries, checks that the flights have a connecting city, and that the first arrives in time for the second. Your method should create an array of potential itineraries that can be returned.  (If it helps, you may assume that this method will never find more than 100 itineraries.) Use the shrinkItineraries() method to "clean up" up the potential itineraries array; see below. Hint: use loops to search for all the flights in the flights variable, check if they meet the criteria, and then create a new Itinerary object if the criteria is met.

shrinkItineraries(...). Takes an array of itineraries, where some of the later indices are unused (null), and returns a new array of itineraries where there are no empty indices. Make this a private method.

Show more
LEARN MORE EFFECTIVELY AND GET BETTER GRADES!
Ask a Question