PLEASE ENSURE TO USE THE FRAMEWORK PROVIDED IN THE IMAGES, AND THAT IT WORKS WITH THE TESTER CLASS. PLEASE DONT EDIT THE TEST CLASS. Simulate a circuit for controlling 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. Provide methods public int getFirstSwitchState() // 0 for down, 1 for up public int getSecondSwitchState() public int getLampState() // 0 for off, 1 for on public void toggleFirstSwitch() public void toggleSecondSwitch()
PLEASE ENSURE TO USE THE FRAMEWORK PROVIDED IN THE IMAGES, AND THAT IT WORKS WITH THE TESTER CLASS. PLEASE DONT EDIT THE TEST CLASS.
Simulate a circuit for controlling 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.
Provide methods
public int getFirstSwitchState() // 0 for down, 1 for up public int getSecondSwitchState()
public int getLampState() // 0 for off, 1 for on
public void toggleFirstSwitch()
public void toggleSecondSwitch()
CODE TEXT SO YOU DON'T HAVE TO TYPE :)
public class Circuit {
private int firstSwitchState; // 0 = down, 1 = up
private int secondSwitchState; // 0 = down, 1 = up
private int lampState; // 0 = off, 1 = on
public Circuit() {
firstSwitchState = 0;
secondSwitchState = 0;
lampState = 0;
}
public void toggleFirstSwitch() {
firstSwitchState = (firstSwitchState == 1) ? (0) : (1);
lampState = (lampState == 1) ? (0) : (1);
}
public void toggleSecondSwitch() {
secondSwitchState = (secondSwitchState == 1) ? (0) : (1);
lampState = (lampState == 1) ? (0) : (1);
}
public int getLampState() {
return lampState;
}
public int getFirstSwitchState() {
return firstSwitchState;
}
public int getSecondSwitchState() {
return secondSwitchState;
}
}
Trending now
This is a popular solution!
Step by step
Solved in 3 steps with 3 images