-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathTV.java
64 lines (51 loc) · 1.12 KB
/
TV.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
public class TV {
//data fields
private int channel;
private int volume;
private boolean on = false;
//no-argument cons
TV(){
this.channel = 1;
this.volume = 20;
}
//method
public void setChannel(int channel) {
if(on) this.channel = channel;
//else System.out.println("No Signal!");
}
public void setVolume(int volume) {
if(on) this.volume = volume;
//else System.out.println("No Signal!");
}
public void channelUp() {
if(on) this.channel++;
//else System.out.println("No Signal!");
}
public void channelDown() {
if(on) this.channel--;
//else System.out.println("No Signal!");
}
public void volumeUp() {
if(on) this.volume++;
//else System.out.println("No Signal!");
}
public void volumeDown() {
if(on) this.volume--;
//else System.out.println("No Signal!");
}
public void powerButton() {
if(on==true) {
this.on = false;
}else {
this.on = true;
}
}
public void info() {
if(on==false) {
System.out.println("TV is off!");
}else {
System.out.println("Current Channel: "+this.channel);
System.out.println("Current Volume: "+this.volume);
}
}
}