The main goal of this project was to create an elevator simulation that transported a certain amount of people until they got to the floor they wanted to. In order to do this we had to implement a Priority Queue in addition to our linked list class. This project was also split into two separate parts: 7A, 7B.
1.) For the first step I had to create a Passenger class which extended cell. This class contained five fields called active, onboard, startFloor, targetFloor, and waitTime. I then had to implement all the passenger methods. Most of these methods were simple getters and setters or checking to see if certain states were occurring. And then I had to overwrite my updateState and draw because it extended cell.
2.) Next I had to create two nested classes within Passenger that implements the comparator interface. Basically the comparator would compare two ints and return either -1, 0, or 1. The MaxFloor class would return a positive value if the target floor of A was larger than B's. Similarly, the MinFloor class would return a positive value if target floor A was smaller than B's.
3.) Now, I had to create a PassengerGroup class that extended my MyPriorityQueue and also implements an iterable. This class had four methods. A constructor, a MaxFloor set comparator, a MinFloor set comparator, and a tostring.
4.) Finally, I had to download a set of provided files in order to test and see if my newly created files were working.
1.) The first step was very simple. All I had to do was to make sure my ElevatorSimulation file created 8 elevators, 25 floors, and 8 passengers per elevator.
2.) For step two I had to find a way to improve the basic elevator code provided to me in part A. While using the High Volume Data Set provided to me, the average amount of timesteps for all passengers to get where they wanted to go was 72. In order to improved this i made some edits within the elevator files.
2A.)The first method I edited was the emptyRule() method. The current method always had the elevator open and close the doors every time it reached the top and bottom. I removed these lines so that it would only open the doors if people were there.
2B.) The second method I edited was the nonEmptyRule. I added an else if statement that checked to see how many people were waiting on each floor. I had it set so that if the there was someone waiting, and the elevator had less than 7 people in it, then it would open its doors.
3.) Next I had to download the High Volume Data Set and run it with my new code. With my new code, I found that I averaged about 57 seconds when running it
(With My Code Edit)
1.) For my extension I chose to number one which asked me to creatively change the display of the simulation. I did this in two ways.
1A.) First, I edited the draw methods of the elevator file so that it would draw passengers images instead of red and yellow dots. Then I edited the LandscapeDisplay file to draw a background image.
1B.) In addition, I also edited the draw function that drew the passengers on the elevator. In this I used a drawString method from the graphics documentation I found online. I converted the number of passengers to a string so that this command would work
Overall, this project proved to be different than the previous ones. I learned to use comparators and how to implement a MyPriorityQueue. In addition, instead of creating all of my own code, I learned how to look at another person's functioning code and find ways to improve it.
Tony Karalekas, Brendan Doyle, CP