Question: Do Practice Exercise E3.3. Name your class Circuit. Solve this without using conditional statements (IF statements) that we have not yet covered. HINTS: * Write
Do Practice Exercise E3.3. Name your class Circuit. Solve this without using conditional statements (IF statements) that we have not yet covered. HINTS: * Write a decision table to show all possible switch combinations and lamp states (represent on as 1 and off as 0). * You can toggle the switches with a calculation (A way to do this involves a look ahead at integer division and modulus (mod) operator %. See section 4.2.3 pp138-9) * You can calculate the status of the lamp given the status of both switches. (There is more than one way to do this. One way involves methods of the Math class).

E3.3 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 getFirstSwitchStateO // 0 for down, 1 for up public int getSecondSwitchStateO public int getLampStateO // 0 for off, 1 for on public void toggleFirstSwitchO public void toggleSecondSwitchO esting E3.4 Write a CircuitTester class that tests all switch combinations in Exercise E3.3, print- ing out actual and expected states for the switches and lamps
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
