A simple elevator
mohayemin opened this issue · 0 comments
mohayemin commented
Overview
An elevator responds to call based on where an elevator is currently located and in which direction it is going.
Example
Assume that the elevator is at level 2 and going to level 5.
- If the up button of level 3 is pressed - it will stop at level 3 and then continue to level 5.
- If the down button of level 3 is pressed - it will go to level 5 without stopping, then come back to level 3 and stop.
Assumptions
- The elevator is for a 5 level building.
- The elevator has three movement types: up, down, stopped.
- The elevator can be at a specific level at a time, no need to consider that it can be in between two levels.
- The elevator can be called only from outside buttons (up/down).
- A single elevator is being controlled by the buttons.
- No need to consider calls from multiple places.
- No need to consider concurrency and multi-threading.
Task
- Write an
Elevator
class. - Write a
call
method in the elevator class, which takes input aButton
, using which it has been called. - The
call
method should returntrue
if the elevator will stop directly,false
if it will first move to its current destination and then accept the call. - Feel free to write additional classes that might be required.
Learning goal
- Encapsulation
Notes
- UI Simulation is not the goal of this problem.
Reminders
- React to the problem if you find it interesting and helpful. This will help others to easily identify good problems to solve.
- Feel free to comment on the problem. Is the description unclear? Do you think it is too easy or too difficult than what is mentioned? Comment about it.
- Discussion about the solution is OK. But do not paste a solution here. Give a link to the solution instead.
- Do you have an interesting problem? Post it.