Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions

Question

What does Processing of an OLAP Cube accomplish?

Answered: 1 week ago