subject

Write a JAVA program that simulates 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 each switch turns the light on or off. (This is called a 3-way switch). Create a class called ThreeWaySwitch which simulates this situation. Provide two instance variables for the states of the two switches at each end of the hallway:

private int firstSwitchState = 0,
secondSwitchState= 0 ;
Provide a constructor with the following heading:

public ThreeWaySwitch(int initialFirstSwitch,
int initialSecondSwitch)
and the following methods:

public int getFirstSwitchState() // 0 = down, 1 = up
public int getSecondSwitchState()
public int getLightState() // 0 = off, 1 = on
public void toggleFirstSwitch()
public void toggleSecondSwitch()
Do not:

provide a third instance variable for the light's state (on or off)
use the ternary operator '?', or any if or switch statements in this class
instead use the '+' and '%' operators (hint: (1 + 1) % 2 = 0)
Write a class named CircuitTester that tests all four switch combinations, printing the status of the two switches and the light for each combination of switches (down/down, up/down, down/up, and up/up).

ansver
Answers: 2

Another question on Computers and Technology

question
Computers and Technology, 22.06.2019 21:00
Ulia is planning to attend the same private four-year college her parents attended. she wants to save at least $18,000 in four years to contribute to her college education. which monthly deposit amounts can julia use to achieve her goal? check all that apply.
Answers: 2
question
Computers and Technology, 23.06.2019 04:31
This graph compares the cost of room and board at educational institutions in texas.
Answers: 1
question
Computers and Technology, 23.06.2019 15:30
Hey so i was just trying out some game hacks so i took a paste from online and built it in my visual studio and then suddenly my computer was working or clicking on stuff on its own am i hacked?
Answers: 1
question
Computers and Technology, 23.06.2019 23:30
What can you prevent issues related to downloading content form the internet
Answers: 1
You know the right answer?
Write a JAVA program that simulates a circuit for controlling a hallway light that has switches at b...
Questions
question
Chemistry, 17.03.2020 17:58
question
English, 17.03.2020 18:00
Questions on the website: 13722363