-
Notifications
You must be signed in to change notification settings - Fork 690
/
TelevisionWork.java
176 lines (161 loc) · 3.69 KB
/
TelevisionWork.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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
import java.util.Scanner;
class Television
{
private boolean pw,mt;
private int vol,chn;
public Television()
{
pw=mt=false;
vol=3;
chn=1;
}
public Television(boolean p,boolean m,int v,int c)
{
pw=p;
mt=m;
if(v>=0&&v<=10)
vol=v;
else
vol=3;
if(c>=1 && c<=99)
chn=c;
else
chn=1;
}
public void power()
{
if(pw==true)
pw=false;
else
pw=true;
}
public void mute()
{
if(pw==false)
return;
mt=!mt;
}
public void volumeUp()
{
if(pw==false)
return;
else
if(vol<10)
vol++;
}
public void volumeDn()
{
if(pw==false)
return;
mt=false;
if(vol>0)
vol--;
}
public void channelUp()
{
if(!pw)
pw=true;
else
{
if(chn<99)
chn++;
else
chn=1;
}
}
public void channelDn()
{
if(!pw)
pw=true;
else
{
if(chn>1)
{
chn--;
}
else
chn=99;
}
}
public void channel(int c)
{
if(!pw)
return;
if(c>=1&&c<=99)
chn=c;
else
System.out.println("Invalid channel");
}
public void show()
{
if(!pw)
{
System.out.println("TV is on");
}
else
{
System.out.println("TV is off");
System.out.println("channel is in"+" "+chn);
if(mt)
{
System.out.println("TV is muted");
}
else
{
System.out.println("volume is in"+" "+vol);
}
}
}
public static void main()
{
Television tv=new Television();
tv.show();
while(true)
{
System.out.println("1. Power on/off");
System.out.println("2. Mute on/off");
System.out.println("3. Voiume up");
System.out.println("4. Volume down");
System.out.println("5. Channel up");
System.out.println("6. Channel down");
System.out.println("7. Channel ");
System.out.println("0. Exit");
int ch;
System.out.println("Enter your choice");
Scanner sc=new Scanner(System.in);
ch=sc.nextInt();
if(ch==0)
break;
switch(ch)
{
case 1:
tv.power();
break;
case 2:
tv.mute();
break;
case 3:
tv.volumeUp();
break;
case 4:
tv.volumeDn();
break;
case 5:
tv.channelUp();
break;
case 6:
tv.channelDn();
break;
case 7:
int c;
System.out.println("Enter your choice");
c=sc.nextInt();
tv.channel(c);
break;
default:
System.out.println("Wrong Choice");
}
tv.show();
}
}
}