airline
Class Flight

java.lang.Object
  extended by airline.Flight
All Implemented Interfaces:
Serializable

public class Flight
extends Object
implements Serializable

Represents a single flight in the airline system. Each flight should have a unique code (e.g., "UA200"). Our model differs from reality in this respect, as we will not allow two different "UA200" entries (e.g., one from LAX to STL and another from STL to BOS).

Author:
Michael Goldwasser
See Also:
Serialized Form

Nested Class Summary
 class Flight.Ticket
          For each passenger on the flight, there is an underlying Ticket that is used to track the seating assignment for the passenger on the flight as well as to trace this passenger back to an original Reservation.
 
Constructor Summary
Flight(String code, String origin, String destination, int numRows, String rowLayout)
          Instantiates a new Flight instance.
 
Method Summary
 Iterator<String> getAllAssignedSeats()
          Returns an Iterator reporting the String designator (e.g., "28C") for each assigned seat, in row-major order.
 Iterator<String> getAllEmptySeats()
          Returns an Iterator reporting the String designator (e.g., "28C") for each empty seat, in row-major order.
 String getDestination()
          Return the airport code for the destination city.
 String getFlightCode()
          Returns the (presumably unique) flight code (e.g., "UA200").
 int getNumberEmptySeats()
          Returns the current number of available seats on the flight.
 String getOrigin()
          Return the airport code for the originating city.
 String getPassenger(String seat)
          Returns the name of the passenger in the given seat.
 Flight.Ticket purchaseTicket(Reservation resv, int travelerNumber)
          Adds the specified traveler from the given Reservation to this flight.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Flight

public Flight(String code,
              String origin,
              String destination,
              int numRows,
              String rowLayout)
       throws IllegalArgumentException
Instantiates a new Flight instance.

Parameters:
code - A unique code for the flight (e.g., "UA200")
origin - Airport code for city of origin (e.g., "STL")
destination - Airport code for destination city (e.g., "STL")
numRows - Number of rows on this flight
rowLayout - Template for row configuration (e.g., "AC_DEFG_HJ")
Throws:
IllegalArgumentException - if rowLayout contains duplicate non-aisle characters.
Method Detail

getAllAssignedSeats

public Iterator<String> getAllAssignedSeats()
Returns an Iterator reporting the String designator (e.g., "28C") for each assigned seat, in row-major order.

Returns:
the Iterator

getAllEmptySeats

public Iterator<String> getAllEmptySeats()
Returns an Iterator reporting the String designator (e.g., "28C") for each empty seat, in row-major order.

Returns:
the Iterator

getDestination

public String getDestination()
Return the airport code for the destination city.

Returns:
airport code for destination city

getFlightCode

public String getFlightCode()
Returns the (presumably unique) flight code (e.g., "UA200").

Returns:
the flight code.

getNumberEmptySeats

public int getNumberEmptySeats()
Returns the current number of available seats on the flight.

Returns:
number of available seats.

getOrigin

public String getOrigin()
Return the airport code for the originating city.

Returns:
airport code for originating city.

getPassenger

public String getPassenger(String seat)
                    throws IllegalArgumentException
Returns the name of the passenger in the given seat. If that seat is empty, returns null.

Parameters:
seat - The seat designation (e.g., "28C")
Returns:
The name of the passenger in the given seat (if any).
Throws:
IllegalArgumentException - if the seat designation is invalid.

purchaseTicket

public Flight.Ticket purchaseTicket(Reservation resv,
                                    int travelerNumber)
Adds the specified traveler from the given Reservation to this flight. If the flight is already full, null is returned. Otherwise a Flight.Ticket is returned with a valid seat assignment.

Parameters:
resv - The Reservation responsible for the original purchase
travelerNumber - An index into the list of travelers on the given Reservation
Returns:
A valid Flight.Ticket if space was available; otherwise null.