cscie160.hw3
Class Floor

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

public class Floor
extends java.lang.Object

CSCIE160

Assignment 2: Elevator part 2

Floor class: This class complements the elevator class for the elevator project.

By David Cheung


Field Summary
 java.util.LinkedList llDown
          llDown
 java.util.LinkedList llResidential
          llResidential
 java.util.LinkedList llUp
          staUp
 
Constructor Summary
Floor(int i)
          Floor constructor:
 
Method Summary
 void addOnePassenger(Elevator myElevator, Passenger aPass)
          addOnePassenger
 int getFloorIdentifier()
          getFloorIdentifier
 void loadPassengers(Elevator myElevator, int numOfPeople)
          loadPassengers
 void loadPassengers(java.util.LinkedList llGetList)
          loadPassenger
 void PrintPassengers()
          PrintPassengers
 java.lang.String toString()
          toString
 void unloadPassengers(Elevator anElevator)
          unloadPassengers:
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

llResidential

public java.util.LinkedList llResidential
llResidential

This list stores passengers when they arrive at the destinated floor.


llUp

public java.util.LinkedList llUp
staUp

this stack stores the passengers that are in the up queue.


llDown

public java.util.LinkedList llDown
llDown

this list stores the passengers that are in the down queue.

Constructor Detail

Floor

public Floor(int i)
Floor constructor:

sets floorIdentifier.

Parameters:
i - The floor number of the floor.
Method Detail

unloadPassengers

public void unloadPassengers(Elevator anElevator)
unloadPassengers:

This Method consists of 2 parts:

The first part is from hw1's stop(). The second part is the new implemented exception feature.

After unloading people in the elevator, this function attempts to board passengers to the elevator if sucessful, then method completes. If elevator happens to be full, then this method will cause Elevator's boardPassenger function to throw an exception. Thus the remaining passengers will be left on the floor.

If the exception was thrown, then a registerRequest to the elevator will be initiated. (Done in Catch)

March 14, 2001: For HW3, when unloading passengers, a collection of passengers is passed to the floor. This is done to replace the old integer representation of the passengers.


addOnePassenger

public void addOnePassenger(Elevator myElevator,
                            Passenger aPass)
addOnePassenger

This method addes one passenger to the queue. Tries to determine if the passenger needs to go down or go up. Then appropiately add the passenger to the correct list.


loadPassengers

public void loadPassengers(Elevator myElevator,
                           int numOfPeople)
loadPassengers

This method is not called by the elevator, but used as test method to load in passengers. Load one passenger at a time.

for HW3: added random generator for destination floors. Assumes that the max floor is seven, which is not seen by Floor.

Parameters:
Elevator - the handle to the elevator
numOfPeople - state how many people to generate.

loadPassengers

public void loadPassengers(java.util.LinkedList llGetList)
loadPassenger

This method is called by the elevator. This passes the whole linklist of passengers from elevator's llPassDestForEachFloor and add it to the current floors' residential list.


toString

public java.lang.String toString()
toString

For debugging use. Returns the numOfPassengers for this floor

Overrides:
toString in class java.lang.Object

PrintPassengers

public void PrintPassengers()
PrintPassengers

prints stats for the passengers


getFloorIdentifier

public int getFloorIdentifier()
getFloorIdentifier

returns the FloorIdentifier of the floor