airline
Class Reservation

java.lang.Object
  extended by airline.Reservation
Direct Known Subclasses:
ProvisionalReservation

public class Reservation
extends Object

A Reservation manages an itinerary of one or more flights for a traveling party.

Author:
Michael Goldwasser

Field Summary
private  Customer booker
          The customer who booked the reservation
private  ArrayList<Flight> legs
          List of legs that are part of this itinerary
private static Random rand
          Used to generate record locators.
private  String recordLocator
          A unique record locator identifying the reservation for the end user
private  Flight.Ticket[][] ticket
          Two-dimensional array of tickets.
private  ArrayList<String> travelers
          A list of names for one or more traveling companions (including the booker)
 
Constructor Summary
protected Reservation(Customer c)
          Creates a new reservation for the given customer.
 
Method Summary
protected  boolean addFlight(Flight f)
          Attempts to add a flight as the next leg of the reservation.
protected  boolean addTraveler(String name)
          Attempts to add a new traveler to the reservation.
protected  void allocateTicketArray()
          Creates the underlying table based upon current number of travelers/legs.
 void cancel()
          Cancels all tickets associated with this reservation.
 Iterator<Flight> getAllLegs()
          Returns an Iterator reporting all flights for this reservation.
 Iterator<String> getAllTravelerNames()
          Returns an Iterator reporting names of all travelers on this reservation.
 Customer getBooker()
          Returns the Customer who booked the reservation.
 Flight getLeg(int index)
          Returns the Flight with the given index.
 String getLocator()
          Return the record locator for this reservation.
 int getNumLegs()
          Returns the number of flight legs booked on this reservation.
 int getNumTravelers()
          Returns the number of travelers booked on this reservation.
 Flight.Ticket getTicket(int travIndex, int legIndex)
          Returns the ticket for the given traveler on the given leg of the reservation.
 String getTravelerName(int index)
          Returns the name of the traveler with given index.
 boolean isPurchased()
          Determines if the given reservation was formally purchased.
protected  void setTicket(int travIndex, int legIndex, Flight.Ticket t)
          Set entry of the underlying array of tickets.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

booker

private Customer booker
The customer who booked the reservation


legs

private ArrayList<Flight> legs
List of legs that are part of this itinerary


rand

private static Random rand
Used to generate record locators.


recordLocator

private String recordLocator
A unique record locator identifying the reservation for the end user


ticket

private Flight.Ticket[][] ticket
Two-dimensional array of tickets. Indexed as ticket[traveler][leg].


travelers

private ArrayList<String> travelers
A list of names for one or more traveling companions (including the booker)

Constructor Detail

Reservation

protected Reservation(Customer c)
Creates a new reservation for the given customer. A Reservation should not be directly instantiated. Instead, an instance of the ProvisionalReservation subclass should be used. The booking customer is automatically deemed the first traveler. A six-letter record locator is randomly generated (it is presumed, but not guaranteed, to be unique).

Parameters:
c - The booking Customer
Method Detail

addFlight

protected boolean addFlight(Flight f)
                     throws IllegalStateException
Attempts to add a flight as the next leg of the reservation. Returns true if successful; false if this flight was already on the reservation.

Parameters:
f - the Flight instance
Returns:
true if successful; false if duplicate flight
Throws:
IllegalStateException - if the reservation has already been purchased.

addTraveler

protected boolean addTraveler(String name)
                       throws IllegalStateException
Attempts to add a new traveler to the reservation. Returns true if successful; false if this traveler was already on the reservation.

Parameters:
name - The name of the traveler
Returns:
true if successful; false if duplicate
Throws:
IllegalStateException - if the reservation has already been purchased.

allocateTicketArray

protected void allocateTicketArray()
                            throws IllegalStateException
Creates the underlying table based upon current number of travelers/legs.

Throws:
IllegalStateException - if already allocated

cancel

public void cancel()
Cancels all tickets associated with this reservation.


getAllLegs

public Iterator<Flight> getAllLegs()
Returns an Iterator reporting all flights for this reservation.

Returns:
the Iterator of Flight instances.

getAllTravelerNames

public Iterator<String> getAllTravelerNames()
Returns an Iterator reporting names of all travelers on this reservation.

Returns:
the Iterator of traveler names.

getBooker

public Customer getBooker()
Returns the Customer who booked the reservation.

Returns:
the booker

getLeg

public Flight getLeg(int index)
Returns the Flight with the given index.

Parameters:
index - Legs of the reservation are zero-indexed
Returns:
the Flight

getLocator

public String getLocator()
Return the record locator for this reservation.

Returns:
String locator.

getNumLegs

public int getNumLegs()
Returns the number of flight legs booked on this reservation.

Returns:
number of flights.

getNumTravelers

public int getNumTravelers()
Returns the number of travelers booked on this reservation.

Returns:
number of travelers.

getTicket

public Flight.Ticket getTicket(int travIndex,
                               int legIndex)
                        throws IllegalStateException
Returns the ticket for the given traveler on the given leg of the reservation. Will return null if unticketed.

Parameters:
travIndex - Traveler names are zero-indexed starting with booking Customer.
legIndex - Flight legs are zero-indexed.
Returns:
The Flight.Ticket instance.
Throws:
IllegalStateException - if the reservation was never purchased.

getTravelerName

public String getTravelerName(int index)
Returns the name of the traveler with given index.

Parameters:
index - Travelers are zero-indexed
Returns:
the name of the traveler.

isPurchased

public boolean isPurchased()
Determines if the given reservation was formally purchased.

Returns:
true if purchased; false otherwise;

setTicket

protected void setTicket(int travIndex,
                         int legIndex,
                         Flight.Ticket t)
                  throws IllegalStateException
Set entry of the underlying array of tickets.

Parameters:
travIndex - traveler index
legIndex - leg index
t - The ticket reference
Throws:
IllegalStateException - if array not allocated.