//Elevator // This models an simple elevator. The elevator goes up, stopping at all // requested floors in the direction that it is going. When it reaches the // limit of its direction (top floor for UP and bottom floor for DOWN), it // changes direction. class Elevator //members public final boolean UP = true public final boolean DOWN = false public final boolean ON = true public final boolean OFF = false public final boolean OPEN = true public final boolean CLOSED = false private boolean direction private int currentFloor private boolean doorStatus private boolean[] floorButtonInElevator private boolean emergencyStopButton private boolean operative private boolean returnToGround private double capacityWt private double currentWt private int MaximumFloorNumber,MinimumFloorNumber //constructor PRECONDITION: none INPUT: two ints, min floor and maximum floor PROCESS: It assigns MinimumFloorNumber to minimum floor and MaximumFloorNumber to maximum floor. It creates the array of size MaximumFloorNumber-MinimumFloorNumber+1 for floorButtonInElevator. It sets all of the floor buttons in the three arrays to be OFF. It sets doorStatus to be OPEN, emergencyStopButton to be OFF, direction to be UP, operative to be ON, returnToGround to be OFF, the currentFloor to be zero, the ground floor, and the currentWt to be zero. OUTPUT: none POSTCONDITION: The array floorButtonInElevator is created and initialized. The doorStatus, direction, emergencyStopButton, operative, returnToGround, and currentFloor are initialized. //query methods getCurrentFloor PRECONDITION: none INPUT: none PROCESS: returns the currentFloor OUTPUT: int, the currentFloor POSTCONDITION: none getDoorStatus PRECONDITION: none INPUT: none PROCESS: returns the doorStatus OUTPUT: boolean, the doorstatus POSTCONDITION: none getEmergencyStopButton PRECONDITION: none INPUT: none PROCESS: returns the emergencyStopButton status OUTPUT: boolean, the emergencyStopButton POSTCONDITION: none getDirection PRECONDITION: none INPUT: none PROCESS: returns the direction OUTPUT: boolean, the direction POSTCONDITION: none getOperative PRECONDITION: none INPUT: none PROCESS: returns the operative status OUTPUT: boolean, the operative POSTCONDITION: none getCurrentWt PRECONDITON: none INPUT: none PROCESS: returns the currentWt OUTPUT: double, the currentWt POSTCONDITION: none getReturnToGround PRECONDITION: none INPUT: none PROCESS: returns the returnToGround status OUTPUT: boolean, the returnToGround POSTCONDITION: none //update methods changeFloor PRECONDITION: doorStatus is CLOSED, emergencyStopButton is OFF, operative is ON, and currentWt is less than capacityWt INPUT: none PROCESS: If elevator is at MaximumFloorNumber and direction is UP, it sets the direction to be DOWN, and sets all of the floorButtonInElevator to be OFF. If the elevator is at the MinimumFloorNumber and the direction is DOWN, it sets the direction to be UP, and sets all of the floorButtonInElevator to be OFF. Otherwise it changes the currentFloor by one in the direction it is going. If the new currentFloor has the corresponding floorButtonInElevator ON, it opens the door and sets the corresponding button to be OFF. If returnToGround is ON and the currentFloor is not the ground floor, it ignores all button requests and keeps the door closed. OUTPUT: none POSTCONDITION: direction, currentFloor, doorStatus, and floorButtonInElevator, could be modifed. openDoor PRECONDITION: elevator is operative INPUT: none PROCESS: changes doorStatus to OPEN OUTPUT: none POSTCONDITION: doorStatus is OPEN closeDoor PRECONDITION: elevator is operative and currentWt is less than capacityWt INPUT: none PROCESS: changes doorStatus to CLOSED OUTPUT: none POSTCONDITION: doorStatus is CLOSED setFloorButton PRECONDITION: floorDesired is not more than MaximumFloorNumber and not less than MinimumFloorNumber. INPUT: int, floorDesired PROCESS: It sets the index of floorInElevator to be ON. OUTPUT: none POSTCONDITION: One of the indices of floorInElevator is set to ON. setEmergencyStopButton PRECONDITION: none INPUT: boolean, the new status PROCESS: emergencyStopButton is set to the new status. OUTPUT: none POSTCONDITION: emergencyStopButton is modified. haltElevator PRECONDITION: none INPUT: none PROCESS: operative is set to OFF. OUTPUT: none POSTCONDITION: operative is OFF. setOperative PRECONDITION: none INPUT: boolean, the new status PROCESS: operative is set to the new status OUTPUT: none POSTCONDITION: operative is modified. returnToGroundFloor PRECONDITION: elevator is operative INPUT: none PROCESS: It sets returnToGround to be ON, and sets direction to be DOWN. OUTPUT: none POSTCONDITION: returnToGround and direction have been modified. enterElevator PRECONDITON: door is open and inputWt + currentWt is less than capacityWt INPUT: double, inputWt PROCESS: It adds the inputWt to the currentWt OUTPUT: none POSTCONDITION: the currentWt is modified exitElevator PRECONDITON: door is open INPUT: none PROCESS: the currentWt is decreased by the exitWt OUTPUT: double, the exitWt POSTCONDITION: the currentWt is modified