Class Train

java.lang.Object
  |
  +--Train

class Train
extends java.lang.Object

Defines a class for making place reservation on a train

Version:
1.0
Author:
CS211 - Spring 2000

Field Summary
private  Carriage[] carriages
          Array for carriages.
private  int currentIndex
          Index of last carriage inserted in the train
private  Carriage currentSaloonCar
          Current Saloon car for making a reservation
private  Carriage currentSleepingCar
          Current Sleeping car for making a reservation
 
Constructor Summary
Train(int maxNoOfCarriages)
          3a) Constructs an array of carriages with maxNoOfCarriages and initializes all instance variables.
 
Method Summary
private  Carriage insertNewCarriage(Carriage thisCarriage)
          3c) Insert a new carriage of the type specified by the parameter thisCarriage.
private  void placeReservation(Carriage currentCarriage, int typePlace)
          3d) Makes a reservation according to the criteria given in the text.
 void placeReservation(int carriageType, int typePlace)
          Makes the reservation in the appropriate carriage with the given type of place.
 void trainSummary()
          3b) Prints out a summary for the train, consisting of: - number of saloon cars in the train.
 
Methods inherited from class java.lang.Object
, clone, equals, finalize, getClass, hashCode, notify, notifyAll, registerNatives, toString, wait, wait, wait
 

Field Detail

carriages

private Carriage[] carriages
Array for carriages.

currentIndex

private int currentIndex
Index of last carriage inserted in the train

currentSaloonCar

private Carriage currentSaloonCar
Current Saloon car for making a reservation

currentSleepingCar

private Carriage currentSleepingCar
Current Sleeping car for making a reservation
Constructor Detail

Train

public Train(int maxNoOfCarriages)
3a) Constructs an array of carriages with maxNoOfCarriages and initializes all instance variables. If input is invalid, error message is printed.
Method Detail

trainSummary

public void trainSummary()
3b) Prints out a summary for the train, consisting of: - number of saloon cars in the train. - number of sleeping cars in the train.

insertNewCarriage

private Carriage insertNewCarriage(Carriage thisCarriage)
3c) Insert a new carriage of the type specified by the parameter thisCarriage. Reference to current sleeping car/saloon car in the train is updated when a new carriage is inserted. Reference to the newly inserted carriage is returned. If an error occurred, error is printed and null is returned.

placeReservation

public void placeReservation(int carriageType,
                             int typePlace)
Makes the reservation in the appropriate carriage with the given type of place.

placeReservation

private void placeReservation(Carriage currentCarriage,
                              int typePlace)
3d) Makes a reservation according to the criteria given in the text. Parameter currentCarriage specifies the carriage which is the current carriage for place reservation. Parameter typePlace specifies the type of the place which is desired. (1) Print out the specified place type. (2) Make the reservation according to the text. (3) Print the following: Carriage plan of the carriage in which reservation is made. Place number, type of the carriage with the carriage number, and the type of place which is actually reserved. Check for possible errors.