Conversation
| * his method will set the human State to TRAVELING. | ||
| * It will give the human the ID of the elevator it entered. | ||
| * Then it will call the requestDestination method, setting the destination. | ||
| * If the elevator arrived at the destination it will set the State to ARRIVED | ||
| * and the ID to null. | ||
| * @param elevatorPanel the system inside the elevator which provides information | ||
| * about the elevator and can be used to request a destination floor. |
There was a problem hiding this comment.
that javadoc is more repeating what the code does than explaining the method on a high level to users
| /** | ||
| * returns the data of the Human class fields. | ||
| * @return the data of the Human class fields. | ||
| */ |
There was a problem hiding this comment.
sorta obsolete javadoc like that
| private final int minFloor; | ||
| private final int floorsServed; | ||
| private int currentFloor; | ||
| private List<Integer> destinations; |
| /** | ||
| * The unique ID of the elevator. | ||
| * | ||
| * @return the unique ID of the elevator | ||
| */ |
There was a problem hiding this comment.
the method already has javadoc through the interface its coming from (@Override)
| * The chosen Elevator will store this destination in it,s arrayList so it knows | ||
| * which direction to move in and when it has arrived. | ||
| * It will not store the same destination twice. |
There was a problem hiding this comment.
a bit too much "implementation details" but ok
| // The elevator is supposed to memorize the destination in a way that | ||
| // it can ensure to eventually reach it. | ||
|
|
||
| if(!destinations.contains(destinationFloor)){ |
There was a problem hiding this comment.
contains on arraylist, a bit problematic perf wise (think about big buildings with lots of humans)
but likely not a big deal in this particular situation as the amount of requests is generally fairly small per elevator
| // create a method that will store the destinations in order: | ||
| // closest to the current floor. So every time an elevator moved one floor, | ||
| // we have to call this method as wel, because humans entering add to the | ||
| // array. |
There was a problem hiding this comment.
dangling comment. potential sign of use of AI? lol
| * Moving the elevator one floor in the correct direction and | ||
| * when it arrived at it,s destination it will remove that floor from | ||
| * it,s arrayList: destinations. |
There was a problem hiding this comment.
bad javadoc: implementation details
| return; | ||
| } | ||
|
|
||
| int destination = destinations.get(0); |
| } | ||
| int calculateDistance = 0; | ||
|
|
||
| Elevator chosenElevator = this.elevators.get(0); |
| if (chosenElevator.getCurrentFloor() < atFloor){ | ||
| calculateDistance = atFloor - chosenElevator.getCurrentFloor(); | ||
| } else if (chosenElevator.getCurrentFloor() > atFloor){ | ||
| calculateDistance = chosenElevator.getCurrentFloor() - atFloor; | ||
| } | ||
|
|
||
| for (Elevator elevator : elevators) { | ||
|
|
||
| int distance = 0; | ||
| if (elevator.getCurrentFloor() < atFloor){ | ||
| distance = atFloor - elevator.getCurrentFloor(); | ||
| } else if (elevator.getCurrentFloor() > atFloor){ | ||
| distance = elevator.getCurrentFloor() - atFloor; | ||
| } | ||
|
|
||
| if (calculateDistance > distance) { | ||
| calculateDistance = distance; | ||
| chosenElevator = elevator; | ||
| } |
There was a problem hiding this comment.
logic duplication. could be rewritten to pick it in a single loop without that extra logic beforehand
Zabuzard
left a comment
There was a problem hiding this comment.
working solution, the logic is overall a bit weak but totally works:
- elevator system assigns closest elevator (based on distance, not travel dir)
- humans enter/exit whenever elevator is at desired floor
- elevators keep a queue of floor requests that they process one by one. problematic with the implementation is that if later requests are already covered by earlier requests that it wont clear them (e.g. at floor 5 going to requested floor 1 should clear a floor 3 request as it moves through it, but doesnt). that leads to elevators having a lot of unecessary traffic. but whatever, it works
- code quality: added javadoc everywhere, cool, but the javadoc is generally of rather low quality/obsolete and often too implementation detailed; variable naming is okay
Submission by user D