-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathElevator.java
More file actions
57 lines (48 loc) · 1.32 KB
/
Copy pathElevator.java
File metadata and controls
57 lines (48 loc) · 1.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
public class Elevator {
public boolean doorOpen=false;
public int currentFloor = 1;
public final int TOP_FLOOR = 5;
public final int BOTTOM_FLOOR = 1;
public void openDoor() {
System.out.println("Opening door.");
doorOpen = true;
System.out.println("Door is open.");
}
public void closeDoor() {
System.out.println("Closing door.");
doorOpen = false;
System.out.println("Door is closed.");
}
public void goUp() {
if (checkDoorStatus()) { // Is door open?
closeDoor();
}
System.out.println("Going up one floor.");
currentFloor++;
System.out.println("Floor: " + currentFloor);
}
public void goDown() {
if (checkDoorStatus()) { // Is door open?
closeDoor();
}
System.out.println("Going down one floor.");
currentFloor--;
System.out.println("Floor: " + currentFloor);
}
public void setFloor(int desiredFloor) {
while (currentFloor != desiredFloor){
if (currentFloor < desiredFloor){
goUp();
}
else {
goDown();
}
}
}
public int getFloor() {
return currentFloor;
}
public boolean checkDoorStatus() {
return doorOpen;
}
}