hockeybro12 / ElevatorChallenge

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

ElevatorChallenge

To use this project, download all the classes provided and compile them in Java using your favorite compiler (DrJava, Eclipse, etc.). Then, run Elevator.java. You will see the output of a sample elevator, that was created in the main method and put into a hashmap. In this very basic test case, 16 elevators were added to the hashmap, and they are all the same. They pick up two people from different floors, and then step forward twice, and then make a change of direction to pick up a person from another floor. A HashMap is good for this situation since it has O(1) lookup time, so you can find the elevators easily and issue requests to them.

The Elevator.java class implements the actual elevator. It does not use FCFS, rather it uses two queues. The queues are ordered based on two custom comparators, one from increasing order and one for decreasing order. As pickup requests are sent in, they are added to either the increasing or decreasing order queue, based on whether they are larger than the current floor or smaller. The queue that the elevator uses is set based on which direction it is moving in. All .java files are included in this project.

About


Languages

Language:Java 100.0%