Question: 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,

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. Togeling 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 i wiring.toggleSwitch(2); wiring.getSwitchState(1); // returns 1 wiring.getSwitchState (2); // returns i wiring.getLampState(); // returns o wiring.toggleSwitch(1); wiring.getSwitchState (1); // returns 0 wiring.getSwitchState(2); // returns 1 wiring.getLampState(); // returns 1 This class models the circuit for a hallway light. */ public class Circuit { // ADD YOUR INSTANCE VARIABLES HERE * Gets the current state of the indicated switch * @param switchNum the number of the switch (1 or 2) @return the state of the indicated switch (n = down, 1 = up) */ public int getSwitchState(int switchNum) { return -1; // FIX ME } Gets the current state of the hallway lamp. @return the state of the lamp ( = off, 1 = on) public int getLampState() { return -1; // FIX ME ) /** Changes the indicated switch from up to down, or vice versa. Toggling the switch also changes the state of the lamp. * @param switch the number of the switch (1 or 2) public void toggleSwitch(int switchNum) { // FILL IN } }
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
