|
|||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--cscie160.hw2.Elevator
CSCIE160
Assignment 2: Elevator part 2
This is a partial simulation of an Elevator by using the sweep algorithm.
By David Cheung
Field Summary | |
Floor[] |
arrayOfFloors
Stores the array of floors that the Elevator travels upon. |
int |
Capacity
The maximum number of people in an Elevator. |
int |
currentDirection
The current direction of the elevator: 1=up, -1=down and 0=not moving. |
int |
currentFloor
The current floor that the Elevator is on. |
boolean[] |
destRequests
Stores the destination requests for each floor and the value would be boolean. |
int |
numOfFloors
The number of floors in the building. |
int[] |
numOfPassDestForEachFloor
Stores the number of passengers destined for each floor. |
int |
numOfPassengers
The number of passengers currently in the elevator |
Constructor Summary | |
Elevator()
Initializes class by creating an array with size of numOfFloors + 1. |
Method Summary | |
void |
boardPassenger(int destFloor)
This increments number of passenger destined there by one, and increase the number of passengers in elevator by one. |
static void |
main(java.lang.String[] argv)
Starts the main part of the class, start with adding passengers in the Elevator and then add a bunch of passengers on some floors. |
void |
move()
Moves Elevator from its current floor to the next floor. |
void |
registerRequest(int numFloor)
Sets the destRequests array. |
void |
stop()
Does not actually stop the elevator in real time but just to allow the simulation to process the numbers when stop is called. |
java.lang.String |
toString()
Prints the current status of the elevator. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
public final int Capacity
public final int numOfFloors
public int currentFloor
public int currentDirection
public int numOfPassengers
public boolean[] destRequests
public int[] numOfPassDestForEachFloor
public Floor[] arrayOfFloors
Constructor Detail |
public Elevator()
Method Detail |
public void move()
Moves Elevator from its current floor to the next floor. This depends on which direction the floor moves.
If the floor is at the top, this will switch the direction of the floor to down (-1) and up (1) if the elevator is at the lowest floor.
Calls the stop function if there is a floor that needs to be stopped.
Calls toString function at the end of this.
stop()
,
toString()
public java.lang.String toString()
Added for HW 2, this prints the number of people on each of the floors of the elevator.
toString
in class java.lang.Object
move()
public void stop()
Does not actually stop the elevator in real time but just to allow the simulation to process the numbers when stop is called.
Now it is changed so that unloadPassengers does the passenger pulling and loading the passengers to the elevator.
Before calling unloadPassenger stop would set the destRequests off for that floor.
Floor.unloadPassengers(Elevator)
public void boardPassenger(int destFloor) throws ElevatorFullException
Called by Floor.unloadPassengers
Floor
- Destination floor for a passenger.Floor.unloadPassengers(cscie160.hw2.Elevator)
public void registerRequest(int numFloor)
numFloor
- The floor number of the floor that is
making the request.Floor.unloadPassengers(cscie160.hw2.Elevator)
public static void main(java.lang.String[] argv)
Used a FOR loop to do a 2 round trip sweep. Note: I used a FOR loop instead of WHILE loop because FOR loop allows me to look at the data after the program ends. Whereas WHILE loop will generate a lot of unnecessary data.
|
|||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |