Class FlytrapAirlines

java.lang.Object
  extended by FlytrapAirlines

public class FlytrapAirlines
extends Object

The main class for FlytrapAirlines.


Field Summary
protected  Hashtable<String,Airport> airports
          A table of Airports.
protected  Graph<Airport,Route> schedule
          The schedule for FTA.
 
Constructor Summary
FlytrapAirlines(String prefix)
           
 
Method Summary
protected  Map<Airport,ComparableAssociation<Integer,Edge<Airport,Route>>> dijkstra(Graph<Airport,Route> g, Airport start)
          An implementation of dijkstra's algorithm to compute route distances.
protected  Map<Airport,ComparableAssociation<Integer,Flight>> dijkstraEarliestArrival(Graph<Airport,Route> g, Airport start, int time)
          An implementation of Dijkstra's algorithm to compute earliest-arriving itineraries.
protected  Airport getAirport(String s)
          Helper method to convert an airport code to a Airport object.
protected  void loadFiles(String prefix)
          Reads in the airports.txt, dists.txt.
static void main(String[] s)
           
protected  void printAirports()
          Handles the "airports" command by printing an alphabetic list of airports serviced by FTA.
protected  void printDistance(Airport departAirport, Airport arriveAirport)
          Handles the "distance" command.
protected  void printFlights(Airport departAirport, Airport arriveAirport)
          Handles the "flights" command.
protected  void printHelp()
          Handles the "help" command by printing a help message.
protected  void printItinerary(Map<Airport,ComparableAssociation<Integer,Flight>> earliestArrivals, Airport destination)
           
protected  void printShortestPath(Map<Airport,ComparableAssociation<Integer,Edge<Airport,Route>>> distances, Airport destination)
           
protected  void printTrip(Airport departAirport, Airport arriveAirport, int earliestDepartTime)
          Handles the "trip" command.
 void processCommands()
          Reads in commands and processes them until "quit" is seen.
protected  void readAirports(String fileName)
          Helper method to read in airport data file.
protected  void readDistances(String fileName)
          Helper method to read in the distances between airports serviced by flights.
protected  void readFlights(String fileName)
          Helper method to read in flight info.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

schedule

protected Graph<Airport,Route> schedule
The schedule for FTA. The vertex labels are Airports, and the edge labels are Routes.


airports

protected Hashtable<String,Airport> airports
A table of Airports. Used for the "airports" command and to convert Strings like "SFO" to Airport objects.

Constructor Detail

FlytrapAirlines

public FlytrapAirlines(String prefix)
Method Detail

processCommands

public void processCommands()
Reads in commands and processes them until "quit" is seen. The valid command formats are described by the help command.


getAirport

protected Airport getAirport(String s)
Helper method to convert an airport code to a Airport object.


printHelp

protected void printHelp()
Handles the "help" command by printing a help message.


printAirports

protected void printAirports()
Handles the "airports" command by printing an alphabetic list of airports serviced by FTA.


printFlights

protected void printFlights(Airport departAirport,
                            Airport arriveAirport)
Handles the "flights" command.


printDistance

protected void printDistance(Airport departAirport,
                             Airport arriveAirport)
Handles the "distance" command. This uses the dijkstra method to compute shortest paths


dijkstra

protected Map<Airport,ComparableAssociation<Integer,Edge<Airport,Route>>> dijkstra(Graph<Airport,Route> g,
                                                                                   Airport start)
An implementation of dijkstra's algorithm to compute route distances. You should not modify this method.


printShortestPath

protected void printShortestPath(Map<Airport,ComparableAssociation<Integer,Edge<Airport,Route>>> distances,
                                 Airport destination)

printTrip

protected void printTrip(Airport departAirport,
                         Airport arriveAirport,
                         int earliestDepartTime)
Handles the "trip" command. This uses the dijkstraEarliestArrival method to compute shortest paths based on arrival time.


dijkstraEarliestArrival

protected Map<Airport,ComparableAssociation<Integer,Flight>> dijkstraEarliestArrival(Graph<Airport,Route> g,
                                                                                     Airport start,
                                                                                     int time)
An implementation of Dijkstra's algorithm to compute earliest-arriving itineraries. You should modify this method to enqueue new possible itineraries into the prioirity queue.


printItinerary

protected void printItinerary(Map<Airport,ComparableAssociation<Integer,Flight>> earliestArrivals,
                              Airport destination)

loadFiles

protected void loadFiles(String prefix)
Reads in the airports.txt, dists.txt. and flights.txt files, prepended with the given prefix. You should call this method only with prefix equals to "large" or "small".

You should not modify this code.


readAirports

protected void readAirports(String fileName)
Helper method to read in airport data file. Adds the airports to the graph and to the airports map


readDistances

protected void readDistances(String fileName)
Helper method to read in the distances between airports serviced by flights. Adds Route edges to the graph.


readFlights

protected void readFlights(String fileName)
Helper method to read in flight info. Adds Flights to the Route object in the graph.


main

public static void main(String[] s)