cscie160.hw3
Class Elevator

java.lang.Object
  |
  +--cscie160.hw3.Elevator

public class Elevator
extends java.lang.Object


Field Summary
static int CAPACITY
           
static int NUM_FLOORS
           
 
Constructor Summary
Elevator()
           
 
Method Summary
 void boardPassenger(cscie160.hw3.Passenger objPerson)
          Board a passenger destined for a floor.
 boolean clearedRequests()
          Check if all elevator requests have been satisfied If so, true is returned, indicating that all passengers have arrived at their destinations, so thee elevator has finished its work and may stop.
 void findDirection()
          Sets the direction of movement floorRequests and the destinations passengers waiting on a floor are checked to determine if the elevator should go up or down.
 int getTravelDirection()
          used by unloadAndLoadPassengers() in class Floor to find the direction of travel of the elevator, and thus determine what passengers should alight the Elevator.
 void go()
          Drive elevator to next destination.
 boolean isElevatorFull()
          Returns true if elevator is at capacity.
static void main(java.lang.String[] mArgv)
          Create an elevator and board two pPassengers into it.
 void move()
          Move elevator one floor in the pTravelDirection.
 void newPerson(int mOnFloor, int mDestFloor)
          Tell class Floor to create a Person object waiting on floor [mFloor] and wanting to go to Floor [mDestFloor]
 void registerRequest(int mFloorNum)
          Register a request for floor [mFloor].
 void setFloorRequests(int mFloor, int mNewValue)
          Needed by loadPassengers() in class Floor to set the floor requests for floor [mFloor] = the number of passengers still on that floor waiting for the elevator [mNewValue] when elevator is full.
 java.lang.String toString()
          Override the toString() method of java.lang.Object for printing Elevator values.
 void unloadPassengers()
          Unload all passengers destined for this floor.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

CAPACITY

public static final int CAPACITY
See Also:
Constant Field Values

NUM_FLOORS

public static final int NUM_FLOORS
See Also:
Constant Field Values
Constructor Detail

Elevator

public Elevator()
Method Detail

move

public void move()
Move elevator one floor in the pTravelDirection.


boardPassenger

public void boardPassenger(cscie160.hw3.Passenger objPerson)
                    throws ElevatorFullException
Board a passenger destined for a floor.

Parameters:
objPerson - reference to the Passenger object boarding the elevator.
ElevatorFullException

unloadPassengers

public void unloadPassengers()
Unload all passengers destined for this floor. The Passenger objects are removed from the Elevators pPassengerList and given to the Floor object to add to its pResidents list.


findDirection

public void findDirection()
Sets the direction of movement floorRequests and the destinations passengers waiting on a floor are checked to determine if the elevator should go up or down. Note: the current floor is ignored, so if the elevator is full and there are still people this floor waiting a loop will not occur.


clearedRequests

public boolean clearedRequests()
Check if all elevator requests have been satisfied If so, true is returned, indicating that all passengers have arrived at their destinations, so thee elevator has finished its work and may stop.

Returns:
true, if all elevator requests have been satisfied.

go

public void go()
Drive elevator to next destination.


toString

public java.lang.String toString()
Override the toString() method of java.lang.Object for printing Elevator values.

Overrides:
toString in class java.lang.Object
Returns:
String a summary of pertinent values in elevartor, including Passengers.

isElevatorFull

public boolean isElevatorFull()
Returns true if elevator is at capacity. (no longer used, but a nice method to have around)

Returns:
true if elevator is at capacity.

setFloorRequests

public void setFloorRequests(int mFloor,
                             int mNewValue)
Needed by loadPassengers() in class Floor to set the floor requests for floor [mFloor] = the number of passengers still on that floor waiting for the elevator [mNewValue] when elevator is full.

Parameters:
mFloor - Floor number being checked for.
mNewValue - Floor number being checked for.

getTravelDirection

public int getTravelDirection()
used by unloadAndLoadPassengers() in class Floor to find the direction of travel of the elevator, and thus determine what passengers should alight the Elevator.

Returns:
direction of Elevator travel

registerRequest

public void registerRequest(int mFloorNum)
Register a request for floor [mFloor].


newPerson

public void newPerson(int mOnFloor,
                      int mDestFloor)
Tell class Floor to create a Person object waiting on floor [mFloor] and wanting to go to Floor [mDestFloor]

Parameters:
mOnFloor - Floor new person is on.
mDestFloor - Floor person wants to go to.

main

public static void main(java.lang.String[] mArgv)
Create an elevator and board two pPassengers into it.