This repository has been archived by the owner on Oct 28, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Door.java
93 lines (78 loc) · 2.09 KB
/
Door.java
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
public class Door {
private String inscription;
private boolean closed;
private boolean locked;
public Door(String i) {
this.inscription = i;
this.closed = true;
this.locked = true;
}
public String getInscription() {
return this.inscription;
}
private void setClosed(boolean value) {
this.closed = value;
}
public boolean isClosed() {
return this.closed;
}
private void setLocked(boolean value) {
this.locked = value;
}
public boolean isLocked() {
return this.locked;
}
public void open() {
if(this.closed == true && this.locked == false) {
this.setClosed(false);
}
else if(this.closed == false){
System.err.println("This door is already open");
}
else if(this.locked == true) {
System.err.println("This door is locked");
}
}
public void close() {
if(this.closed == false) {
this.setClosed(true);
}
else {
System.err.println("This door is already closed");
}
}
public void lock() {
if(this.locked == false) {
this.setLocked(true);
}
else {
System.out.println("This door is already locked");
}
}
public void unlock() {
if(this.locked == true) {
this.setLocked(false);
}
else {
System.out.println("This door is already unlocked");
}
}
public void printString() {
String i;
String l;
String c;
if(this.getInscription() == null || this.getInscription() == "")
i = "This door has no inscription\n";
else
i = "This door is labeled " + this.getInscription() + "\n";
if(this.isLocked())
l = "This door is locked\n";
else
l = "This door is unlocked\n";
if(this.isClosed())
c = "This door is closed\n";
else
c= "This door is open\n";
System.out.println(i + l + c);
}
}