Java - TP4
Instructions
- Groups of 1 or 2 students
- Inter-group plagiarism will be severely punished
- Due Date: Friday 10 April at 5pm
- 1 point deducted for each half-hour delay
- In a README file, indicate:
- your full names
- list the questions that have been completed or not. Feel free to add comments
- Zip folder
tp4and load it on Moodle- Don’t include target folder
Your code must be functional, with no compilation or runtime errors.
Don’t forget to include the javadoc and to comment your code if necessary.
- Everything you need is in the course and the practical exercises
- You are permitted to conduct internet searches to find information and documentation
- The use of any LLM is strictly prohibited during this exam
- As Olivier R. so rightly says: LLMs are good servants, but bad masters
- They can be useful tools, but they must not replace your own comprehension and programming skills
If you are caught using an LLM, it will be considered cheating and you will receive a zero.
Launch service VSCode Java
Update your repository
Perhaps the repository used as a template has been updated since the last practical session.
Service interruptions are possible. To prevent data loss, back up your code regularly with Git.
After each part, create a commit and push your code to the remote repository.
When you’ve finished
1 Subject
In this project, you will model and simulate the operation of elevators in a small hotel. The goal is to design a simple object-oriented system where people appear on different floors, request an elevator, travel to their destination, and exit when they arrive.
This topic is inspired by Elevator Saga.
2 Questions
2.1 Simulation setup
The Main class is used to run the simulation. Here, you define the hotel, its floors, and the elevators, then run the simulation.
Each step, people may arrive on each floor to call an elevator.
It’s annoying to have to enter one by one elevators and floors. It would be easier just to specify the number you want.
In the Person class, a value depends on the number of floors.
In the Elevator class:
2.2 Request an elevator
When someone reaches a floor, they press the button to call an elevator.
For now, all these calls are sent to the first elevator.
-
- if an elevator is already on its way to that floor, do nothing
- otherwise, find the least busy elevator and add the floor to the end of its destinations list
2.3 Target Floor
On each floor, people may arrive randomly.
You may have noticed in the simulation that some people arrive on floor n and want to go to floor n.
Perhaps, like children, they find it fun to take the elevator, but to make the simulation more realistic:
2.4 Unit test
Let’s write some unit tests with JUnit (no need for Mockito).
2.5 Crazy Elevator
It wasn’t specified yet, but we are in a haunted hotel where the elevators sometimes go crazy.
At each step, a crazy elevator can, with equal probability:
- remain stationary
- skip its next destination and go directly to the next one
- go to the next floor as a normal elevator
Half the time, a crazyElevator may decide not to unload its passengers.
If it is full, it will send all its passengers into another dimension.
2.6 Elevator Direction
We would like to know at all times whether the elevator is going up, down or is idle (inactive).
-
- choose the appropriate type
+-------+--------------------------+--------------------------+----------------------+
| Floor | Elevator1 ↑ | Elevator2 ↓ | waitingPersons |
+-------+--------------------------+--------------------------+----------------------+
| 3 | | | |
| 2 | | | g3 |
| 1 | | [ ] | |
| 0 | [e2 ] | | f2 |
+-------+--------------------------+--------------------------+----------------------+