-
Notifications
You must be signed in to change notification settings - Fork 0
/
DeskPhone.java
45 lines (38 loc) · 1.15 KB
/
DeskPhone.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
public class DeskPhone implements ITelephone {
private int myNumber;
private boolean isRinging;
public DeskPhone(int myNumber) {
this.myNumber = myNumber;
}
// We have to implement below methods because we have implemented ITelephone Interface in which all these methods are
// declared. If we don't implement them here, we will get an error.
@Override
public void powerOn() {
System.out.println("No action taken, desk phone does not have a power button.");
}
@Override
public void dial(int phoneNumber) {
System.out.println("Now ringing " + phoneNumber + " on desk phone");
}
@Override
public void answer() {
if (isRinging) {
System.out.println("Answering the desk phone");
isRinging = false;
}
}
@Override
public boolean callPhone(int phoneNumber) {
if (phoneNumber == myNumber) {
isRinging = true;
System.out.println("Ring Ring");
} else {
isRinging = false;
}
return isRinging;
}
@Override
public boolean isRinging() {
return isRinging;
}
}