-
Notifications
You must be signed in to change notification settings - Fork 4
Submission D #9
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Submission D #9
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sorta obsolete javadoc like that
| private final int minFloor; | ||
| private final int floorsServed; | ||
| private int currentFloor; | ||
| private List<Integer> destinations; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(extra space)
| /** | ||
| * The unique ID of the elevator. | ||
| * | ||
| * @return the unique ID of the elevator | ||
| */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
bad javadoc: implementation details
| return; | ||
| } | ||
|
|
||
| int destination = destinations.get(0); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
prefer getFirst()
| } | ||
| int calculateDistance = 0; | ||
|
|
||
| Elevator chosenElevator = this.elevators.get(0); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(prefer getFirst())
| 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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