Class ParkingLot

java.lang.Object
  extended byParkingLot

public class ParkingLot
extends Object

This class models a parking lot. The ParkingLot maintains a list of Cars in the lot, and lets the Cars come and go. It has an infinite number of parking spots, but it's a little inconvenient to use because the most recent Car to arrive is the only one that can leave. After it is gone, then the Car that arrived before it can leave, and so on. Thus, the first Car to arrive cannot leave until all other Cars have left.


Constructor Summary
ParkingLot()
          A new ParkingLot object does not have any cars on it, initialize appropriately.
 
Method Summary
 int getCarCount()
          Return the number of Cars presently in the ParkingLot.
 void parkCar(ArrayList cars)
          Park several Cars in the lot (ie, add them to the end of the list of cars currently in the lot).
 void parkCar(Car car)
          Park one Car in the lot (ie, add it to the end of the list of cars currently in the lot).
 Car unparkCar()
          Take the last car that was parked out of the lot.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ParkingLot

public ParkingLot()
A new ParkingLot object does not have any cars on it, initialize appropriately.

Method Detail

parkCar

public void parkCar(Car car)
Park one Car in the lot (ie, add it to the end of the list of cars currently in the lot).

Parameters:
car - the Car to park

parkCar

public void parkCar(ArrayList cars)
Park several Cars in the lot (ie, add them to the end of the list of cars currently in the lot).

Parameters:
cars - a List of Cars to park

unparkCar

public Car unparkCar()
Take the last car that was parked out of the lot. The last Car is removed from the list and a reference to it is returned to the caller. If there are no Cars in the lot, null is returned.

Returns:
the last car parked or null if the lot is empty

getCarCount

public int getCarCount()
Return the number of Cars presently in the ParkingLot.

Returns:
the number of Cars presently in the ParkingLot.