-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmenu_power.java
148 lines (117 loc) · 3.37 KB
/
menu_power.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
/* Design a class Room that has properties AC_ON, HOME_THEATRE_ON, FAN_ON and LIGHT_ON that stores Boolean values to indicate whether the appliance is ON or OFF. Design a menu driven program in java that puts ON/OFF the corresponding appliances and gives appropriate message. If the total power consumed is more than 2kW, show a message Overload. Assume AC consumes 1200 watts, Home Theatre consumes 600 watts,
Fan consumes 400 watts and light consumes 100 watt. */
import java.util.Scanner;
class Room
{
private Boolean AC_ON,HOME_THEATER_ON,FAN_ON,LIGHT_ON;
private int power;
Room()
{
power =0;
AC_ON = false;
HOME_THEATER_ON = false;
FAN_ON = false;
LIGHT_ON =false;
}
public String getAC()
{
if(AC_ON) return "ON";
else
return "OFF";
}
public String getTheater()
{
if(HOME_THEATER_ON) return "ON";
else
return "OFF";
}
public String getFan()
{
if(FAN_ON) return "ON";
else
return "OFF";
}
public String getLight()
{
if(LIGHT_ON) return "ON";
else
return "OFF";
}
public int getPower()
{
return power;
}
public void setAC_ON()
{
if(AC_ON) {
AC_ON = false;
power -= 1200;
}
else {
AC_ON = true;
power += 1200;
}
}
public void setHOME_THEATER_ON()
{
if(HOME_THEATER_ON){
HOME_THEATER_ON = false;
power-=600;
}
else {
HOME_THEATER_ON = true;
power += 600;
}
}
public void setFAN_ON()
{
if(FAN_ON) {
FAN_ON = false;
power -= 400;
}
else {
FAN_ON = true;
power += 400;
}
}
public void setLIGHT_ON()
{
if(LIGHT_ON)
{
LIGHT_ON=false;
power-=100;
}
else {
LIGHT_ON = true;
power += 100;
}
}
public void checkOverload()
{
if(power>2000) System.out.println("\nWARNING! POWER OVERLOAD");
}
}
public class PowerMenu{
public static void main(String[] args) {
Scanner s = new Scanner(System.in);
Room r = new Room();
int n;
while(true) {
System.out.println("MENU");
System.out.println("1. Enter 1 to (ON/OFF) AC : CURRENT STATUS (AC) ---> " + r.getAC());
System.out.println("2. Enter 2 to (ON/OFF) HOME THEATER : CURRENT STATUS (HOME THEATER)---> " + r.getTheater());
System.out.println("3. Enter 3 to (ON/OFF) FAN : CURRENT STATUS (FAN) ---> " + r.getFan());
System.out.println("4. Enter 4 to (ON/OFF) LIGHT : CURRENT STATUS (LIGHT) ---> " + r.getLight());
System.out.println("5. Enter 0 to exit TOTAL POWER CONSUME ---> " + r.getPower());
r.checkOverload();
n = s.nextInt();
switch (n) {
case 1 -> r.setAC_ON();
case 2 -> r.setHOME_THEATER_ON();
case 3 -> r.setFAN_ON();
case 4 -> r.setLIGHT_ON();
case 0 -> System.exit(0);
}
}
}
}