Practice with Objects

Work through the detailed steps below to complete this program.

ELEVATOR 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

In the Elevator class make the following static (class level) variables:

Make all but the last one (powerOn) constants so that they can't be changed. Hint: look up "final"

Make the following instance (object level) variables:

 

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

Make two constructors

You'll be using both of them.

Make two(?) static methods

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).

Make instance methods:

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.

In the ElevatorTest class:

Do the following:

 

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.