Write a class program based on the information given below. This class will simulate the operation of an elevator. The elevator can travel between 1st and 15th floors of the building it is situated in.
Class Name:
Attributes:
- private int currentFloor;
- private static final int MAXFLOOR = 15;
ONE Constructor:
- to set the value of currentFloor to 1. This method does not have any parameters.
ONE Member method:
- void request (int newFloor)
-This method will be used to alter the position of the elevator. This method consists of an if-else statement having three parts:
If an incorrect floor number (i.e. newFloor) is given, no action is taken;
if a floor above the current position is selected, the elevator moves up;
and if a floor below the current position is selected, the elevator moves down.
For the movement up and down, the method can use while loop to update the position one floor at a time and report the elevator’s movement using System.out.println().
For example, if an object of Elevator calls the request method as below:
<object>.request(6);
<object>.request(3);
then, the following output will be displayed for the above call:
Starting at floor 1
Going up - now at floor 2
Going up - now at floor 3
Going up - now at floor 4
Going up - now at floor 5
Going up - now at floor 6
Stopping at floor 6
Starting at floor 6
Going down - now at floor 5
Going down - now at floor 4
Going down - now at floor 3
Stopping at floor 3