airline
Class Flight.Ticket

java.lang.Object
  extended by airline.Flight.Ticket
Enclosing class:
Flight

public class Flight.Ticket
extends Object

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.

Author:
Michael Goldwasser

Field Summary
private  Reservation resv
          The underlying reservation for the purchase of this seat.
private  String seat
          Seat assignment.
private  int travelerNum
          An index for the individual traveler, relative to Reservation.getTravelers().
 
Constructor Summary
private Flight.Ticket(Reservation res, int traveler, String seat)
          Initialize an underlying seat assignment that will be given as a reference to the Reservation when booking the seat.
 
Method Summary
 void cancel()
          Officially removes the underlying traveler from the given flight.
 Flight getFlight()
          Returns a reference to the associated Flight.
 String getSeat()
          Returns the string representation of the seat (e.g., "28C").
 String getTravelerName()
          Returns the name of the traveler for this ticket.
 boolean requestSeatChange(String seatDesignator)
          Requests a seat change from the existing assignment to the designated seat.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

resv

private Reservation resv
The underlying reservation for the purchase of this seat.


seat

private String seat
Seat assignment.


travelerNum

private int travelerNum
An index for the individual traveler, relative to Reservation.getTravelers().

Constructor Detail

Flight.Ticket

private Flight.Ticket(Reservation res,
                      int traveler,
                      String seat)
Initialize an underlying seat assignment that will be given as a reference to the Reservation when booking the seat. It is read-only for public, but can be instantiated and modified from within the Flight class.

Parameters:
res - Reference to the underling Reservation holding this seat
traveler - Index into the array of travelers on given reservation
seat - Seat designation (e.g., "28C"); assumed to be valid
Method Detail

cancel

public void cancel()
            throws IllegalArgumentException
Officially removes the underlying traveler from the given flight. This causes the ticket to be invalid, and returns the seat to be empty;

Throws:
IllegalArgumentException - if the Ticket was invalid (for example, if previously removed from flight)

getFlight

public Flight getFlight()
Returns a reference to the associated Flight.

Returns:
Flight instance.

getSeat

public String getSeat()
Returns the string representation of the seat (e.g., "28C").

Returns:
assigned seat

getTravelerName

public String getTravelerName()
Returns the name of the traveler for this ticket.

Returns:
traveler name.

requestSeatChange

public boolean requestSeatChange(String seatDesignator)
                          throws IllegalArgumentException
Requests a seat change from the existing assignment to the designated seat. If the seat designator is ill-formed or already assigned to another passenger, the request is denied.

Parameters:
seatDesignator - String representation for desired seat (e.g., "28C")
Returns:
true if request accepted; false otherwise (e.g., if that seat is unavailable)
Throws:
IllegalArgumentException - if seatDesignator is invalid for the flight's seating configuration.