Class Carriage

java.lang.Object
  |
  +--Carriage
Direct Known Subclasses:
SaloonCar, SleepingCar

public abstract class Carriage
extends java.lang.Object

This abstract class defines a carriage.

Version:
1.0
Author:
CS211 - Spring 2000

Field Summary
private  int carriageNumber
          Carriage number
private  boolean[][] carriagePlan
          Plan for carriage.
private  int noOfColumns
          Number of columns in a carriage
private  int noOfRows
          Number of rows in a carriage
private  int[] noOfVacantPlaces
          Array to keep track numbers of vacant places of each type of place.
 
Constructor Summary
Carriage(int carriageNo, int rows, int columns)
          1a) Constructs a new Carriage class that initializes the carriageNumber, noOfRows, noOfColumns, carriagePlan, and noOfVacantPlaces.
 
Method Summary
 void drawCarriagePlan(int placeNo)
          1j) Draw the plan of the carriage.
private  int findRowNoOfFirstVacantPlace(int typePlace)
          1g) Find row-number of the first vacant place of the specified type in the carriage.
 int getCarriageNo()
          1b) Returns carriage number of the carriage.
abstract  java.lang.String getNameOfTypePlace(int typePlace)
          Abstract method that returns the name of the type of place
 boolean hasVacantPlace(int typePlace)
          1d) Checks if the carriage has vacant places of the type specified in the parameter.
 boolean isFull()
          1e) Check if the carriage is full.
private  int placePositionToPlaceNo(int i, int j)
          1h) Convert (i,j)-pair in the plan to place number in the carriage.
 int reserveFirstVacantPlace(int typePlace)
          1i) Reserve the first vacant place of the specified type.
private  void setOccupied(int i, int j)
          1c) Sets the given place in the carriage plan to occupied.
 int typePlaceWithLeastOccupancy()
          1f) Find the type of place in the carriage which has least occupancy and returns -1 if the carriage is full.
 
Methods inherited from class java.lang.Object
, clone, equals, finalize, getClass, hashCode, notify, notifyAll, registerNatives, toString, wait, wait, wait
 

Field Detail

carriageNumber

private int carriageNumber
Carriage number

noOfRows

private int noOfRows
Number of rows in a carriage

noOfColumns

private int noOfColumns
Number of columns in a carriage

carriagePlan

private boolean[][] carriagePlan
Plan for carriage. true indicates occupied. false indicates vacant.

noOfVacantPlaces

private int[] noOfVacantPlaces
Array to keep track numbers of vacant places of each type of place.
Constructor Detail

Carriage

public Carriage(int carriageNo,
                int rows,
                int columns)
1a) Constructs a new Carriage class that initializes the carriageNumber, noOfRows, noOfColumns, carriagePlan, and noOfVacantPlaces.
Method Detail

getCarriageNo

public int getCarriageNo()
1b) Returns carriage number of the carriage.

setOccupied

private void setOccupied(int i,
                         int j)
1c) Sets the given place in the carriage plan to occupied. Update the count of different type of vacant places.
Parameters:
(i,j) - Place location.

hasVacantPlace

public boolean hasVacantPlace(int typePlace)
1d) Checks if the carriage has vacant places of the type specified in the parameter.

isFull

public boolean isFull()
1e) Check if the carriage is full.

typePlaceWithLeastOccupancy

public int typePlaceWithLeastOccupancy()
1f) Find the type of place in the carriage which has least occupancy and returns -1 if the carriage is full.

findRowNoOfFirstVacantPlace

private int findRowNoOfFirstVacantPlace(int typePlace)
1g) Find row-number of the first vacant place of the specified type in the carriage. If there are no vacant places of the specified type, return -1.
Parameters:
typePlace - Type of Place.
Returns:
int The row number found.

placePositionToPlaceNo

private int placePositionToPlaceNo(int i,
                                   int j)
1h) Convert (i,j)-pair in the plan to place number in the carriage.
Parameters:
(i,j) - Place location pair.
Returns:
int Place Number.

reserveFirstVacantPlace

public int reserveFirstVacantPlace(int typePlace)
1i) Reserve the first vacant place of the specified type. Returns place number in the carriage. Returns -1 if no vacant place found.

drawCarriagePlan

public void drawCarriagePlan(int placeNo)
1j) Draw the plan of the carriage. Specified place number is shown with *. Occupied places are shown with +. Vacant places are shown with -.

getNameOfTypePlace

public abstract java.lang.String getNameOfTypePlace(int typePlace)
Abstract method that returns the name of the type of place