2 30 ** 4 * This class models the circuit for a hallway light. 5 */ 6 public class Circuit { 7 8 // ADD YOUR INSTANCE VARIABLES HERE 9. ** 100 11 * Gets the current state of the indicated switch * 12...


Java. Please use the template in the picture.


2<br>30<br>**<br>4<br>* This class models the circuit for a hallway light.<br>5<br>*/<br>6 public class Circuit {<br>7<br>8<br>// ADD YOUR INSTANCE VARIABLES HERE<br>9.<br>**<br>100<br>11<br>* Gets the current state of the indicated switch<br>*<br>12<br>@param switchNum the number of the switch (1 or 2)<br>@return the state of the indicated switch (0 = down, 1 = up)<br>*<br>13<br>*<br>14<br>15<br>* /<br>160<br>17<br>public int getSwitchState(int switchNum) {<br>return -1; // FIX ME<br>}<br>18<br>19<br>20<br>210<br>22<br>/ **<br>* Gets the current state of the hallway lamp.<br>23<br>@return the state of the lamp (0 = off, 1 = on)<br>*<br>24<br>25<br>*/<br>public int getLampState() {<br>return -1; // FIX ME<br>260<br>27<br>28<br>}<br>29<br>30<br>310<br>/ **<br>* Changes the indicated switch from up to down, or vice versa. Toggling the<br>* switch also changes the state of the lamp.<br>32<br>33<br>*<br>34<br>@param switch the number of the switch (1 or 2)<br>*<br>35<br>36<br>370<br>*/<br>public void toggleSwitch(int switchNum) {<br>// FILL IN<br>}<br>39<br>40 }<br>41<br>O m m 3<br>

Extracted text: 2 30 ** 4 * This class models the circuit for a hallway light. 5 */ 6 public class Circuit { 7 8 // ADD YOUR INSTANCE VARIABLES HERE 9. ** 100 11 * Gets the current state of the indicated switch * 12 @param switchNum the number of the switch (1 or 2) @return the state of the indicated switch (0 = down, 1 = up) * 13 * 14 15 * / 160 17 public int getSwitchState(int switchNum) { return -1; // FIX ME } 18 19 20 210 22 / ** * Gets the current state of the hallway lamp. 23 @return the state of the lamp (0 = off, 1 = on) * 24 25 */ public int getLampState() { return -1; // FIX ME 260 27 28 } 29 30 310 / ** * Changes the indicated switch from up to down, or vice versa. Toggling the * switch also changes the state of the lamp. 32 33 * 34 @param switch the number of the switch (1 or 2) * 35 36 370 */ public void toggleSwitch(int switchNum) { // FILL IN } 39 40 } 41 O m m 3
Problem 6: Circuit<br>Implement a class Circuit that simulates a hallway light that has switches at both ends of the hallway. Each switch<br>can be up or down, and the light can be on or off. Toggling either switch turns the lamp on or off. All switches start out<br>down, and the lamp starts out off.<br>The class's template is provided here: Circuit.java . Fill in the places marked with placeholder text in the template.<br>Note: It is possible to implement a solution that does not use conditionals (which you have not learned yet in this class).<br>However, you are welcome to use conditionals if you choose.<br>Examples:<br>Circuit wiring<br>new Circuit();<br>wiring.getSwitchState (1); // returns 0<br>wiring.getSwitchState (2); // returns 0<br>wiring.getLampState ( ); // returns 0<br>wiring.toggleSwitch(1);<br>wiring.getSwitchState (1); // returns 1<br>wiring.getSwitchState (2); // returns 0<br>wiring.getLampState ( ); // returns 1<br>wiring.toggleSwitch(2);<br>wiring.getSwitchState (1); // returns 1<br>wiring.getSwitchState (2); // returns 1<br>wiring.getLampState (); // returns 0<br>wiring.toggleSwitch(1);<br>wiring.getSwitchState (1); // returns 0<br>wiring.getSwitchState (2); // returns 1<br>wiring.getLampState (); // returns 1<br>

Extracted text: Problem 6: Circuit Implement a class Circuit that simulates a hallway light that has switches at both ends of the hallway. Each switch can be up or down, and the light can be on or off. Toggling either switch turns the lamp on or off. All switches start out down, and the lamp starts out off. The class's template is provided here: Circuit.java . Fill in the places marked with placeholder text in the template. Note: It is possible to implement a solution that does not use conditionals (which you have not learned yet in this class). However, you are welcome to use conditionals if you choose. Examples: Circuit wiring new Circuit(); wiring.getSwitchState (1); // returns 0 wiring.getSwitchState (2); // returns 0 wiring.getLampState ( ); // returns 0 wiring.toggleSwitch(1); wiring.getSwitchState (1); // returns 1 wiring.getSwitchState (2); // returns 0 wiring.getLampState ( ); // returns 1 wiring.toggleSwitch(2); wiring.getSwitchState (1); // returns 1 wiring.getSwitchState (2); // returns 1 wiring.getLampState (); // returns 0 wiring.toggleSwitch(1); wiring.getSwitchState (1); // returns 0 wiring.getSwitchState (2); // returns 1 wiring.getLampState (); // returns 1
Jun 08, 2022
SOLUTION.PDF

Get Answer To This Question

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here