airline
Class ProvisionalReservation

java.lang.Object
  extended by airline.Reservation
      extended by airline.ProvisionalReservation

public class ProvisionalReservation
extends Reservation

This subclass of Reservation is used to represent a tentative reservation in its intermediate stages while being constructed by a Customer.

Author:
Michael Goldwasser

Constructor Summary
ProvisionalReservation(Customer c)
          Creates a new ProvisionalReservation for this customer.
 
Method Summary
 boolean addFlight(Flight f)
          Attempts to add a flight as the next leg of the reservation.
 boolean addTraveler(String name)
          Attempts to add a new traveler to the reservation.
 boolean purchase()
          Attempts to purchase tickets for this reservation.
 
Methods inherited from class airline.Reservation
allocateTicketArray, cancel, getAllLegs, getAllTravelerNames, getBooker, getLeg, getLocator, getNumLegs, getNumTravelers, getTicket, getTravelerName, isPurchased, setTicket
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ProvisionalReservation

public ProvisionalReservation(Customer c)
Creates a new ProvisionalReservation for this customer. 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

public boolean addFlight(Flight f)
                  throws IllegalStateException
Description copied from class: Reservation
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.

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

addTraveler

public boolean addTraveler(String name)
                    throws IllegalStateException
Description copied from class: Reservation
Attempts to add a new traveler to the reservation. Returns true if successful; false if this traveler was already on the reservation.

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

purchase

public boolean purchase()
                 throws IllegalStateException
Attempts to purchase tickets for this reservation. The process is carried out in an all-or-nothing manner. If a single ticket cannot be purchased, then no tickets should be purchased (more accuately, any tickets that had been purchased should be immediately cancelled).

Returns:
true if successful; false otherwise.
Throws:
IllegalStateException - if the reservation was already purchased or if there are zero travelers or zero legs.