cscie160.hw2
Class Elevator

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

public class Elevator
extends java.lang.Object


Field Summary
static int CAPACITY
           
static int NUM_FLOORS
           
 
Constructor Summary
Elevator()
           
 
Method Summary
 void boardPassenger(int mDestinationFloor)
          Board a passenger destined for a floor.
 int findDirection()
          Return the direction of closest destination floor, with preference for moving down.
 int getNumPassengersDestForFloor(int mFloor)
          Return the # of passengers destined for floor [mFloor].
 void go()
          Drive elevator to next destination.
 boolean isElevatorFull()
          Return 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 registerRequest(int mFloorNum, boolean mCreateThatPerson)
          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.
 void stop()
          Stop the elevator and unload pPassengers destined for this floor.
 java.lang.String toString()
          Override the toString() method of java.lang.Object for printing Elevator values.
 void unloadPassenger()
          Unload a passenger.
 
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(int mDestinationFloor)
                    throws ElevatorFullException
Board a passenger destined for a floor.

Parameters:
mDestinationFloor - The floor that passenger wants to go to.
ElevatorFullException

unloadPassenger

public void unloadPassenger()
Unload a passenger.


stop

public void stop()
Stop the elevator and unload pPassengers destined for this floor.


registerRequest

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

Parameters:
mCreateThatPerson - If true put a person on that floor waiting.

findDirection

public int findDirection()
Return the direction of closest destination floor, with preference for moving 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. If the elevator is full then floor requests should probably be ignored and only floor destinations looked at. (for later)

Returns:
Direction of closest destination floor.

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:
summary of pertinent values in elevartor.

isElevatorFull

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

Returns:
true if elevator is at capacity.

getNumPassengersDestForFloor

public int getNumPassengersDestForFloor(int mFloor)
Return the # of passengers destined for floor [mFloor]. Called by unloadAndLoadPassengers() in class Floor.

Parameters:
mFloor - Floor number being checked for.
Returns:
# of passengers destined for floor [mFloor]

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.

main

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