Question: import java.util.*; public class Lights { boolean L1; boolean L2; public Lights(boolean x) { L1 = x; L2 = x; } public void displayStatus() {
import java.util.*; public class Lights { boolean L1; boolean L2; public Lights(boolean x) { L1 = x; L2 = x; } public void displayStatus() { if (L1 == true) { System.out.println("L1 is on"); } else if (L1 == false) { System.out.println("L1 is off"); } if (L2 == false) { System.out.println("L2 is on "); } else if (L2 == true) { System.out.println("L2 is off"); } } } class Simulator { public static void main(String[] args) { Scanner console = new Scanner(System.in); System.out.println("Do want lamps on or off"); String s = console.nextLine(); boolean x = true; if (s.equals("on")) { x = true; } if (s.equals("off")) { x = false; } Lights L1 = new Lights(x); Lights L2 = new Lights(x); L1.displayStatus(); L2.displayStatus(); } }
why is output being printed twice and how do i fix it
in java with in depth explanation
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
