-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDisco.java
171 lines (134 loc) · 4.77 KB
/
Disco.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
package com.company.oldAssignments;
/** This class represents a disco ball made from 4 light bulbs.
* Each light bulb's color is defined by the colors red, green and blue.
*
* @author Neta Oren
* @since 06/04/2016
* @version 0.1
*/
public class Disco {
LightBulb _bulb1 = new LightBulb(new RGBColorOld());
LightBulb _bulb2 = new LightBulb(new RGBColorOld());
LightBulb _bulb3 = new LightBulb(new RGBColorOld());
LightBulb _bulb4 = new LightBulb(new RGBColorOld());
/** This constructor recieves four light bulbs as parameters.
* It sets the color of this light bulb to the given light bulb's color.
*
* @param b1 - Light bulb no. 1
* @param b2 - Light bulb no. 2
* @param b3 - Light bulb no. 3
* @param b4 - Light bulb no. 4
*/
public Disco (LightBulb b1, LightBulb b2, LightBulb b3, LightBulb b4) {
this._bulb1.setColor(b1._color);
this._bulb2.setColor(b2._color);
this._bulb3.setColor(b3._color);
this._bulb4.setColor(b4._color);
}
/** This method returns the value of the first bulb.
*
* @return The value of the first bulb.
*/
public LightBulb getFirstBulb () {
return this._bulb1;
}
/** This method returns the value of the second bulb.
*
* @return The value of the second bulb.
*/
public LightBulb getSecondBulb () {
return this._bulb2;
}
/** This method returns the value of the third bulb.
*
* @return The value of the third bulb.
*/
public LightBulb getThirdBulb () {
return this._bulb3;
}
/** This method returns the value of the fourth bulb.
*
* @return The value of the fourth bulb.
*/
public LightBulb getFourthBulb () {
return this._bulb4;
}
/** This method recieves a number of a bulb and changes its switched value to its opposite.
* If the bulb is on, it turns it off. If the bulb is off, it turns it on.
*
* @param num - Represents the number of the bulb.
*/
public void switchBulb (int num) {
final int NO_BULB = 0;
final int FIRST_BULB = 1;
final int SECOND_BULB = 2;
final int THIRD_BULB = 3;
final int FOURTH_BULB = 4;
if (num <= FOURTH_BULB && num > NO_BULB)
{if (num == FIRST_BULB)
this._bulb1.switchLight();
if (num == SECOND_BULB)
this._bulb2.switchLight();
if (num == THIRD_BULB)
this._bulb3.switchLight();
if (num == FOURTH_BULB)
this._bulb4.switchLight();
}
}
/** This method turns on all the bulbs at once.
*/
public void turnAllOn () {
if (this._bulb1.isSwitchedOn() == false)
this._bulb1.switchLight();
if (this._bulb2.isSwitchedOn() == false)
this._bulb2.switchLight();
if (this._bulb3.isSwitchedOn() == false)
this._bulb3.switchLight();
if (this._bulb4.isSwitchedOn() == false)
this._bulb4.switchLight();
}
/** This method turns off all the bulbs at once.
*/
public void turnAllOff () {
if (this._bulb1.isSwitchedOn() == true)
this._bulb1.switchLight();
if (this._bulb2.isSwitchedOn() == true)
this._bulb2.switchLight();
if (this._bulb3.isSwitchedOn() == true)
this._bulb3.switchLight();
if (this._bulb4.isSwitchedOn() == true)
this._bulb4.switchLight();
}
/** This method checks whether all light bulbs are on and returns true or false accordingly.
*
* @return True or false whether all light bulbs are on.
*/
public boolean areAllOn () {
if (this._bulb1.isSwitchedOn() == true && this._bulb2.isSwitchedOn() == true
&& this._bulb3.isSwitchedOn() == true && this._bulb4.isSwitchedOn() == true)
return true;
else
return false;
}
/** This method checks whether all light bulbs are off and returns true or false accordingly.
*
* @return True or false whether all light bulbs are off.
*/
public boolean areAllOff () {
if (this._bulb1.isSwitchedOn() == false && this._bulb2.isSwitchedOn() == false
&& this._bulb3.isSwitchedOn() == false && this._bulb4.isSwitchedOn() == false)
return true;
else
return false;
}
/** This method checks whether all light bulbs are the same color and returns true or false accordingly.
*
* @return True or false whether all light bulbs are the same color.
*/
public boolean allSameColor () {
if (this._bulb1 == this._bulb2 && this._bulb2 == this._bulb3 && this._bulb3 == this._bulb4)
return true;
else
return false;
}
}