Question: The Light Panel class contains the instance variable panel which is a two-dimensional array containing integer values that represent the state of lights on




The Light Panel class contains the instance variable panel which is a two-dimensional array containing integer values that represent the state of lights on a grid. The two-dimensional array may be of any size. Lights may be on, off, or in an error state. The instance variable on value represents an integer value for the on state of a light. The instance variable of fValue represents an integer value for the off state of a light. The onValue and offValue instance variables may be of any valid integer value. Any other integer value in the panel array represents an error state for a light. (9 points) Here is the partially completed Light Panel class: public class Light Panel { private int ( ) ( )] panel; private int onValue; private int offValue; public LightPanel (int () () p, int on, int off) { panel=p; onValue = on; offValue = off; } public boolean isColumnError (int column) { //returns true if the column contains 1 or more lights in error //returns false if the column has no error lights //to be implemented in part a } public void fixError () { // to be implemented in part b } //there may be other instance variables, constructors, and methods not shown } Given the example for the panel array below: 3 3 8 8 8 3 4 8 0 3 80 For this example, onValue = 8, offValue = 3 and all other values are errors. There are five array elements with the onValue of 8, thus there are five lights on. There are four array elements with the off value of 3, thus there are four lights off. There are three array elements with other values, thus there are three locations on the panel with errors. Part A: The Boolean method is ColumnError takes an integer parameter for a column of panel and determines if there exists a light in an error state for that column. The method returns true if one or more lights of the column are in an error state and returns false if there are no lights in an error state. Thus a call to isColumnError (0) would return true because column 0 contains a light with an error value of 4 because it is not on(8) or off(3). A call to isColumnError (1) returns false because all lights in column 1 are either on(8) or off(3). Write the is ColumnError method below: //precondition: panel, onValue and off value have been initialized //postcondition: method returns true if col of the panel array contains one or more lights in an error state and false if col of the panel array has no lights in an error state. public boolean is ColumnError (int col) { Part B: The fixError method will repair any column of panel containing an error state. Any column of panel containing an error state will copy the contents of the column immediately to the right of it (note that this column may also contain errors). If the last column on the right contains an error state, it will copy the contents of the first column on the left. For example, given the panel array with contents: 3 3 8 8 8 3 0 3 4 8 8 0 For this example, onValue = 8 and offValue = 3; A call to fixError () would result in the following modification to the panel array: 3 3 8 8 8 3 0 3 0 4 8 8 The first column contains 3, 8, 4 where 4 is an error state so the contents of the second column are copied over. 3 3 8 8 3 3 0 3 8 8 80 The second column contains 3, 3, 8 which has no errors, so no changes are made. The third column contains 8, 0, 8 where 0 is an error state so the contents of the third column are copied over. 3 3 8 3 8 3 3 3 8 800 Notice the third column still contains an error that will not be fixed. The last column contains 8, 3, 0 where O is an error state. So, the contents of the first column (which was modified in the first step) are copied to the last column. 3 3 8 3 3 3 3 3 8 8 0 8 The above array is the final value of the panel array after the call to fixError ( ) completes. Write the fixError( ) method below. Public void fixError( ) { } The Light Panel class contains the instance variable panel which is a two-dimensional array containing integer values that represent the state of lights on a grid. The two-dimensional array may be of any size. Lights may be on, off, or in an error state. The instance variable on value represents an integer value for the on state of a light. The instance variable of fValue represents an integer value for the off state of a light. The onValue and offValue instance variables may be of any valid integer value. Any other integer value in the panel array represents an error state for a light. (9 points) Here is the partially completed Light Panel class: public class Light Panel { private int ( ) ( )] panel; private int onValue; private int offValue; public LightPanel (int () () p, int on, int off) { panel=p; onValue = on; offValue = off; } public boolean isColumnError (int column) { //returns true if the column contains 1 or more lights in error //returns false if the column has no error lights //to be implemented in part a } public void fixError () { // to be implemented in part b } //there may be other instance variables, constructors, and methods not shown } Given the example for the panel array below: 3 3 8 8 8 3 4 8 0 3 80 For this example, onValue = 8, offValue = 3 and all other values are errors. There are five array elements with the onValue of 8, thus there are five lights on. There are four array elements with the off value of 3, thus there are four lights off. There are three array elements with other values, thus there are three locations on the panel with errors. Part A: The Boolean method is ColumnError takes an integer parameter for a column of panel and determines if there exists a light in an error state for that column. The method returns true if one or more lights of the column are in an error state and returns false if there are no lights in an error state. Thus a call to isColumnError (0) would return true because column 0 contains a light with an error value of 4 because it is not on(8) or off(3). A call to isColumnError (1) returns false because all lights in column 1 are either on(8) or off(3). Write the is ColumnError method below: //precondition: panel, onValue and off value have been initialized //postcondition: method returns true if col of the panel array contains one or more lights in an error state and false if col of the panel array has no lights in an error state. public boolean is ColumnError (int col) { Part B: The fixError method will repair any column of panel containing an error state. Any column of panel containing an error state will copy the contents of the column immediately to the right of it (note that this column may also contain errors). If the last column on the right contains an error state, it will copy the contents of the first column on the left. For example, given the panel array with contents: 3 3 8 8 8 3 0 3 4 8 8 0 For this example, onValue = 8 and offValue = 3; A call to fixError () would result in the following modification to the panel array: 3 3 8 8 8 3 0 3 0 4 8 8 The first column contains 3, 8, 4 where 4 is an error state so the contents of the second column are copied over. 3 3 8 8 3 3 0 3 8 8 80 The second column contains 3, 3, 8 which has no errors, so no changes are made. The third column contains 8, 0, 8 where 0 is an error state so the contents of the third column are copied over. 3 3 8 3 8 3 3 3 8 800 Notice the third column still contains an error that will not be fixed. The last column contains 8, 3, 0 where O is an error state. So, the contents of the first column (which was modified in the first step) are copied to the last column. 3 3 8 3 3 3 3 3 8 8 0 8 The above array is the final value of the panel array after the call to fixError ( ) completes. Write the fixError( ) method below. Public void fixError( ) { }
Step by Step Solution
There are 3 Steps involved in it
public boolean isColumnErro... View full answer
Get step-by-step solutions from verified subject matter experts
