Answered step by step
Verified Expert Solution
Question
1 Approved Answer
class Lamp { boolean isOn; public Lamp() { this.isOn = false; } public Lamp(boolean isOn) { ; } public void turnOn() { this.isOn = ;
class Lamp { boolean isOn; public Lamp() { this.isOn = false; } public Lamp(boolean isOn) { ; } public void turnOn() { this.isOn = ; } public void () { this.isOn = false; } public void flip() { this.isOn = ; } public isOn() { return this.isOn; } public void setLamp(boolean ) { this.isOn = isOn; } @Override public String toString() { String out; if (this.isOn) else out = String.format("%3s", "OFF"); return out; } @Override public boolean equals( obj) { Lamp other = (Lamp) obj; if (isOn != other.isOn) return false; return true; } }
Homework C-1: Get the Lamp class working. Write a Java program that creates an array of 30 Lamps that are randomly set to either On or Off. Write out all of the Lamps using 5 columns. Then flip the switch on each of the first 10 lamps, turn the next 10 off, and the final 10 on. Write out all the lamps again. Use a display method to write out the array of lampsStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started