Work through the detailed steps below to complete this program.
You'll be making two classes similar to the Toyota and CarTest classes that we did in class.
So, one class, Elevator.java contains all of the properties and methods that create and control the elevator.
The other class ElevTest.java is a class which has the main() method.
This class will create the elevators and make them do things. The Elevator class does not have main().
Put comments at the top of each class: your name, date, program information
Make all but the last one (powerOn) constants so that they can't be changed. Hint: look up "final"
Make all of these variables private.
Set the default values: floor=1; people=0; doorsOpen=false; direction=+1
Note: you can also set default values in constructors
You'll be using both of them.
Make some sort of method for turning the building power on or off (and checking if it is on or off). It has to be static so that it affects the whole building.
The method should print out a message ONLY if the state changes. If the power is already on and you try turning it on, nothing happens. But if it is OFF and you turn it ON, then in prints "Building power restored" (or similar).
All of these methods should print out error messages if something is wrong. They should not print out messages if they do what they are supposed to do.
when moving the elevator:
You can have some variation of methods to move the elevator, as long as the functionality is basically the same. ie. maybe you don't need up()
and down()
@Override
.If you can't figure out how to write the toString() method, have a look in the HTML source of this page. You'll find a version there as a comment.
Type "CTRL-U" to see page source. Then go to line 110 or so, you'll see the toString method there
Do the following:
The following are examples of things you can try with your elevator.
You're basically testing out the functionality of each method to see if they work as they are supposed to:
print out toString each time someone gets on or off the elevator
· if you want to print out toString anywhere else, you can.
Optional: try and set both elevators to exactly the same state and then see if they are equal. They won't be since == does not work for objects. You would have to use .equals() but there is no .equals() in the Elevator class (yet) and the Object.equals() does not help. So we would have to write our own .equals() method.
I was trying to see if I could make a graphical display of the elevators, but it is too hard just using text output. It could be done using a GUI.