Question: You will be implementing the Iterator Design Pattern to view flights. Code must follow logic of the uml diagram. Don't edit the driver except to
You will be implementing the Iterator Design Pattern to view flights. Code must follow logic of the uml diagram. Don't edit the driver except to add a package iterator. Please make the files Airline.java, Flight.java, FlightIterator.java
AirlineDriver
import java.util.Iterator;
import java.util.Scanner;
public class AirlineDriver
public AirlineDriver
Airline american new AirlineAmerican Airlines";
Scanner reader new ScannerSystemin;
System.out.print
Enter Origin Airport Code: ;
String fromCode reader.nextLine;
System.out.printEnter Destination Airport Code: ;
String toCode reader.nextLine;
Iterator flights american.createIteratorfromCode toCode;
System.out.println;
ifflights null
return;
whileflightshasNext
System.out.println flights.next;
public static void mainString args
AirlineDriver driver new AirlineDriver;
Airport
public enum Airport
ATLHartsfieldJackson Atlanta International Airport"
DFWDallasFort Worth International Airport"
DENDenver International Airport"
ORDChicagos OHare International Airport"
LAXLos Angeles International Airport"
JFKJohn F Kennedy International Airport"
LASHarry Reid International Airport in Las Vegas"
MCOOrlando International Airport"
MIAMiami International Airport"
CLTCharlotte Douglas International Airport"
SEASeattleTacoma International Airport"
PHXPhoenix Sky Harbor International Airport"
EWRNewark Liberty International Airport"
SFOSan Francisco International Airport"
IAHHoustons George Bush Intercontinental Airport"
BOSBostons General Edward Lawrence Logan International Airport"
FLLFort LauderdaleHollywood International Airport"
MSPMinneapolisSt Paul International Airport"
LGALaGuardia Airport in New York"
DTWDetroit Metro Wayne County Airport";
public final String label;
private AirportString label
this.label label;
Output
Enter Origin Airport Code: CLT
Enter Destination Airport Code: SEA
CLT to SEA ::h m Direct Flight
CLT to SEA ::h m Direct Flight
CLT to SEA ::h m Direct Flight
CLT to SEA ::h m Transfers
CLT to SEA ::h m Stopover
CLT to SEA ::h m Transfers
Invalid:
Enter Origin Airport Code: sdd
Enter Destination Airport Code: dfs
Must enter valid airport codes
Flights
B CLT SEA, ::
T CLT ATL, ::
B CLT JFK::
B CLT SEA, ::
T CLT ATL, ::
B CLT JFK::
B CLT SEA, ::
T CLT ATL, ::
B CLT JFK::
B CLT SEA, ::
T CLT ATL, ::
B CLT JFK::
B CLT SEA, ::
T CLT ATL, ::
B CLT JFK::
B CLT SEA, ::
FlightLoader
import java.ioFile;
import java.ioFileNotFoundException;
import java.time.LocalTime;
import java.util.ArrayList;
import java.util.Scanner;
public class FlightLoader
relative path to the file, based on the directory you currently have open
private static final String FILENAME "iteratorflightstxt;
Returns a list of all Flights from the text file
@return An ArrayList of Flights
public static ArrayList getFlights
ArrayList flights new ArrayList;
try
File file new FileFILENAME;
Scanner scanner new Scannerfile;
loop through to get each question
while scannerhasNextLine
String data scanner.nextLinesplit;
String flightNum datatrim;
Airport from getAirportdatatrim;
Airport to getAirportdatatrim;
LocalTime startTime LocalTime.parsedatatrim;
LocalTime endTime LocalTime.parsedatatrim;
int numTransfers Integer.parseIntdatatrim;
flights.addnew FlightflightNum from, to startTime, endTime, numTransfers;
scanner.close;
catch FileNotFoundException e
System.out.printlnSorry we could not properly read the questions file";
eprintStackTrace;
catchException e
eprintStackTrace;
return flights;
private static Airport getAirportString data
return Airport.valueOfdatatrimtoUpperCase;
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
