-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLight.java
More file actions
100 lines (78 loc) · 1.93 KB
/
Light.java
File metadata and controls
100 lines (78 loc) · 1.93 KB
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
/**
Adoga Haruna
*/
public class Light extends ElectricalAppliance
{
public static final String LED = "LED";
public static final String Halogen = "Halogen";
public static final String EnergySaving = "EnergySaving";
private String type;
private int lifeInHours;
boolean failureStatus;
public Light (String name ,String type, int macAddress, int rating, String location, boolean status)
{
super(name, macAddress, rating, location, status);
failureStatus = false;
this.type = type;
if (type.equals(LED))
{
lifeInHours = 10;
}
else if (type.equals(Halogen))
{
lifeInHours = 5;
}
else if (type.equals(EnergySaving))
{
lifeInHours = 7;
}
}
public void setFailureStatus(boolean status)
{
this.failureStatus = status;
}
public boolean getFailureStatus ()
{
return failureStatus;
}
public String getType ()
{
return type;
}
public void setType(String type)
{
this.type = type;
}
public void setLifeInHours (int life)
{
lifeInHours = life;
}
public int getLifeInHours ()
{
return lifeInHours;
}
public void setStatus (boolean status)
{
if(status == true)
{
lifeInHours = lifeInHours - 1;
if (lifeInHours == 0) {
failureStatus = true;
}
}
super.setStatus(status);
}
public String toString ()
{
String failureStat;
if (failureStatus == false)
{
failureStat = "Working";
}
else
{
failureStat = "Has failed";
}
return super.toString()+ ", the life is: " + lifeInHours+ ", the failure status is: " + failureStat;
}
}