use dr java make sure it work For this assignment, you will be writing a class called Light that represents a single light bulb. Download
use dr java make sure it work
For this assignment, you will be writing a class called Light that represents a single light bulb. Download the template file, Light.java, as a starting point.
Your job is to add code to Light.java so that your implementation meets the requirements specified below. To complete the assignment, replace all the /* missing code */ comments in the file with your own code. You do not need to change any other code in the file.
In previous assignments, we had a requirement that your class be named Main. In this assignment, the class is required to be named Light.
Light.java includes a main method that will help test your code. In order to fully test the Light class, you will need to add more test cases to the main method. At a minimum, run the main to make sure your implementation output matches the sample run listed below. We will test your code using our own main method that is similar to the one provided.
When you are done coding and testing, copy and paste your entire Light class (including the main method) into the Code Runner and press "Submit" in order for your assignment to count as turned in.
Variables:
boolean on - Represents whether the light bulb is on or off. Set to true if the light bulb is on, false if off.
boolean burntOut - Represents whether the light is burnt out or working properly. Set to true if the light bulb is burnt out, false if it is working.
String color - Represents the color of the light bulb with possible values of "red", "blue", "green" and "white". No other color values are allowed.
Methods:
Light() - Default constructor that sets the bulb to on, not burnt out, and "white".
Light(boolean o, boolean b, String c) - This constructor sets the on variable to the parameter o. The burntOut variable is set to the parameter b. If burntOut is true, on is set to false, no matter what value is stored in o. The color variable is set to c only if c is "red", "green" or "blue". The constructor ignores the case of the value in c, and stores the value as a lower-case String. If c holds any value other than "red", "green" or "blue", color will be set to "white".
String toString () - returns a String with the Light in the format: red off burnt out green on not burnt out Notice there is a tab between the value for color and "off"/"on", and one space before the "burnt out" or "not burnt out".
void flip() - This method changes the bulb from on to off, or visa versa. If the burntOut variable is true, then the on variable may only be set to false.
String getColor() - This method returns the color of the light bulb.
void setColor(String c) - The color variable is set to c only if c is "red", "green" or "blue", ignoring case. The value stored for color should be lower case. If c holds any value other than "red", "green" or "blue" (ignoring case), the method sets the color to "white".
boolean isOn() - Returns true if on, false otherwise.
void burnOut() - Sets burntOut to true.
Sample Run:
1. Test Light() *** PASS: on is set correctly (true) *** PASS: burntOut is set correctly (false) *** PASS: color is set correctly (white) *** PASS: toString produced the correct output (white on not burnt out) 2. Test Light(boolean b, boolean o, String c) *** PASS: on is set correctly (false) *** PASS: burntOut is set correctly (true) *** PASS: color is set correctly (green) *** PASS: toString produced the correct output (green off burnt out) 3. Test burnOut() *** PASS: on is set correctly (false) *** PASS: burntOut is set correctly (true) *** PASS: color is set correctly (white) *** PASS: toString produced the correct output (white off burnt out) 4. Test flip() light3 is on *** PASS: on is set correctly (true) *** PASS: burntOut is set correctly (false) *** PASS: color is set correctly (white) *** PASS: toString produced the correct output (white on not burnt out) now light3 should be off *** PASS: on is set correctly (false) *** PASS: burntOut is set correctly (false) *** PASS: color is set correctly (white) *** PASS: toString produced the correct output (white off not burnt out) now light3 should be back on *** PASS: on is set correctly (true) *** PASS: burntOut is set correctly (false) *** PASS: color is set correctly (white) *** PASS: toString produced the correct output (white on not burnt out) light1 is burned out and off, we can't flip it on *** PASS: on is set correctly (false) *** PASS: burntOut is set correctly (true) *** PASS: color is set correctly (white) *** PASS: toString produced the correct output (white off burnt out) 5. Test isOn() *** PASS: isOn() working properly *** PASS: isOn() working properly 6. Test getColor() *** PASS: getColor() working properly 7. Test setColor(String) PASS: color is set correctly (red) PASS: color is set correctly (blue) PASS: color is set correctly (white)
Step by Step Solution
There are 3 Steps involved in it
Step: 1
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