Handson Exam
Elevators
Write an Elevator class (Elevator.java) for the following
program .
An Elevator object represents a typical elevator in a building.
An elevator can load and unload passengers,
and move up and down the building.
Assume that the building that houses these elevators have 5 floors,
numbered 1 through 5.
The number of passengers allowed in an elevator is dependent
on the elevator's total weight limit and the passengers' average weight,
which are fixed at 2000 1000 lbs and 123.45 123.5 lbs, respectively.
At any point,
you would like to be able to find out the current floor
the elevator is on, the number of passengers in the
elevator, and the elevator's total passenger weight.
The up and down methods of the elevator have an int
argument representing the number of floors the elevator will move.
The load and unload methods also have an int parameter
representing the number of passengers
entering or leaving the elevator.
The elevator must prevent the entry of passengers
that cause the total weight limit to be exceeded.
For the sample program, this output should result.
Use BlueJ so that you could test your Elevator objects visually.
Include the
ElevatorSimulation program
in the BlueJ project so that you can test and compare
against the expected output
(Create an ElevatorSimulation class,
and then cut and paste the code from the link).
You should be able to infer which methods
need to be present in the Elevator class from the
ElevatorSimulation program.
Nevertheless, the methods are:
- up: move up x floors, where x is the int parameter.
If x is too large that it causes the elevator to go past the 5th floor,
the elevator should end up on the 5th floor.
- down: move down x floors, where x is the int parameter.
If x is too large that it causes the elevator to go past the 1st floor,
the elevator should end up on the 1st floor.
- load: let in an additional p persons in the elevator.
If p is such that it will cause the elevator to exceed its limit,
then let in only enough persons that the elevator can handle.
- unload: let out p persons from the elevator.
It is ridiculous for p to be more than the actual number of
persons in the elevator, but if this is the case,
everyone in the elevator leaves.
- getPassengerCount:
return the number of passengers currently in the elevator.
- getTotalWeight:
return the total weight of passengers currently in the elevator.
(assume an average weight of 123.45).
- getCurrentFloor:
return the number of the floor that the elevator is on.
You do not have to worry about negative-valued parameters.
Zip your BlueJ project (name it HO1xxxxxx.zip where xxxxxx is your id number)
and submit through moodle