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

Other questions on the subject: Computers and Technology

image
Computers and Technology, 22.06.2019 11:00, tristina20
The isometric projection camera technique provides an illusion of perspective by using things like parallax scrolling to create the illusion of 3d in a 2d game
Answers: 3
image
Computers and Technology, 22.06.2019 12:10, drelisech6467
Linux is distributed under gnu gpl. why is this important? a. it ensures that only torvalds can profit from the sale of linux b. it prevents unknowledgeable users from downloading programs they don't know how to operate. c. it provides protection for the developers who created linux. d. it states that anyone can copy, modify, and share the program if changes are made public.
Answers: 1
image
Computers and Technology, 24.06.2019 13:30, sweeps8758
Which type of excel chart should be used to track students’ progress on test grades? line column bar pie
Answers: 2
image
Computers and Technology, 24.06.2019 22:00, kingkush85
Difference between ancient and modern mode of information transmission
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 in other subjects:

Konu
Mathematics, 31.01.2020 14:47