The simulation has some global elements that all things can access
string log [] this holds everything that the elevator is doing, it is also what the visualizer uses to per frameRequest outsideRequests []Request finsihedRequests []The simulation holds a request maker, elevator, and operator. It foes in the following order.
Startup() //sets everything upoutsideRequests.add(Request.new()) * May change to accomadate wait times betweenElevator.canTakeNewRequests() returns true,Elevator.stopAtFloor(Elevator.pickFloorToStopAt())Elevator.moveTowardsGoal()Elevator.checkFloorStatus()stop() //tears everything downThis sets up the elevators, requests, log, etc
A log request happens on
Elevator.stopAtFloor()Elevator.pickUp()Elevator.dropOff()Elevator.moveTowardsGoal()A log request tracks
insideRequestsoutsideRequestscurrentFloorgoalThere are two types of requests. Outside requests and inside requests. The elevator can choose how to handle them. An outside request is a request that a user makes when they ask the elevator to pick them up. An inside request is the request that the user makes once they are picked up and inside of the elevator.
When an outside request is handled, a corresponding inside request is made.
int outsideWaitint insideWait
int getOutsideRequest()
int getInsideRequest()
startOutsideWait() starts the timer for the outisde of the elevator. This gets called on construction.
startInsideWait() starts the timer for inside of the elevator. This is called on pickUp().endWait() ends the inside wait. This is called on dropOff().This elevator has one job: Stopping at a floor. This means it stops at a floor and whoever is on that floor gets dropped off or picked up.
int currentFloor tracks the current floor the elevator is onint goal tracks the last stopAtFloor(int floor) requestbool isFree tracks if the elevator can take new requestsRequest insideRequests [] tracks the accepted insideRequestsIt has the following functions which can be used by the operator
Abstract: pickFloorToStopAt() gets rewritten in the child (which anyone can make). It returns a floor number.getOutsideRequests() returns a copy of the outside requests as an int[] using getOutsideRequest()getInsideRequests() returns a copy of the inside requests as an int[] using getInsideRequest()getCapacity() returns the maximum an elevator can hold. This is a constant.getOccupancy() returns how many users are in an elevator. This is calculated by the length of inside requests.The elevator also has functions that the operator cannot use
stopAtFloor(int floor) sets the goal for the elevator to stop at. Sets isFree to false.dropOff(int floor) "drops off" any inside requests by marking them as handled and moving them to a finished list. This is called in stopAtFloor(int floor)pickUp(int floor) "picks up" (capacity - occupancy) users at the specified floor (outside request) by moving that many outside requests to inside requests. This is called in stopAtFloor(int floor) after dropOff(int floor) and floor is passed through.canTakeNewRequests() returns isFree.moveTowardsGoal() increments or decrements towards goal from currentFloor.Elevator.checkFloorStatus() sets isFree to true if currentFloor == goal.To know which floor to stop at, it gets requests from the users. When user sends a request, it is put in the queue of the elevator. A request tells the elevator someone wants to be picked up or dropped off. An elevator may only have as many inside requests as its capacity.
This saves the log to a file and downloads it to the computer