Question: 16. ^MUST CONTAIN while() statement to ALLOW multiple input^ ****PLEASE INCLUDE COMMENTS IN CODE (so that I can understand why you did certain things)***** Obiective
16.


^MUST CONTAIN while() statement to ALLOW multiple input^
****PLEASE INCLUDE COMMENTS IN CODE (so that I can understand why you did certain things)*****
Obiective Write a program that reads in lines from the input. For every pair of line, it creates Lamp objects and operates on them as per instructions in the lines. Then, it prints out information on the status of each Lamp. The important part of this assignment is to make use of the Lamp class. Details are given after an explanation of what the program is to do. NOTE THAT AT THE END OF THIS DOCUMENT THERE ARE INSTRUCTIONS ON HOW TO CREATE A ZIP FILE USING ECLISPE THAT YOU CAN UPLOAD TO cyoj-207.cs.iastate.edu for this problem input The input will be one or more PAIRS of lines. Each pair of lines will have on the first line names of lights and on the second line will have the states of the lines. The first line will have an integer followed by that many strings consisting of names of colors. Example: 2 green gray The second line will have for each lamp a 0 or 1.A 0 will signify that the lamp is to be turned OFF and a 1 will indicate that the particular lamp is to turned ON. Example: 2 green gray followed by 1 1 will indicate that both the green and the gray lamps are to be turned on. Output Each pair of input lines will be followed by ONE line of output indicating the status of the lamps described in the input. In the above example, the output will be "green is ON gray is ON" Sample Input 2 green gray 1 orange green is ON gray is ON orange is OFF Now that you know what this program is to do, let us get into more details of what you need to do. See next page You will need to write code for TWO classes (aLamp class and a Main class) 1. The Lamp class should have TWO instance variables a boolean variable to indicate the status of the Lamp a String variable that will indicate the name of the Lamp 2. The Lamp class should have FIVE methods a. a constructor public Lamp(String s) that will set the name of the Lamp to the String s b. public void turnon() that will set the status of the Lamp to true c. public void turnoff) that will set the status of the Lamp to false d. public boolean ison) that will return the value of the status e. public String toString) that will return a String consisting of name isON" (if the Lamp's status is true) OR name is " "OFF" (if the Lamp's status is false) Main class The Main class should have the main method (public static void main(String args) ) The main method should keep reading lines 1. // process the FIRST line of the pair a. it should read in the number of lamps b. then it should read in the names of the lamps, create a new Lamp, and store the lamps in an array 2. I/ process the second line of the pair a. Next, it should read in an int from the line and take a turnOn or turnoff action on the particular Lamp (which is in the array). It should do this for all the lamp:s 3. // print the output a. traverse the lamp array and print each lamp (use System.out.print(Lamp 4. remember to print a final println after printing the lamps
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
