Question: The program contains a main for the program. This can be left unedited. You can add more code if you like, but do NOT delete

The program contains a main for the program. This can be left unedited. You can add more code if you like, but do NOT delete or change any code already written.

SectionProblemLog.java has a number of places that indicate YOUR CODE GOES HERE. It will be your job to insert code at those points to make the methods works as indicated. See the sample jar file for details on formatting toString (it is 'X' for true and '_' for false).

public static void main(String[] args) { final boolean X = true; final boolean O = false; boolean[][] grid = {{O, X, X, O, X, O, X, X, X, O}, {O, X, X, O, O, X, O, O, X, O}, {X, O, X, O, O}, {O, X, O, O, O, O, X, O, X}}; SectionProblemLog log = new SectionProblemLog(grid); System.out.println(log); System.out.println(); System.out.println("The number correct in each section is:"); try{ log.setCompleted(true, 3, 5); for(int row = 1; row < SectionProblemLog.NUMBER_OF_SECTIONS; row++) { System.out.println(row + ": " + log.numberCorrectInSection(row)); } } catch(IndexOutOfBoundsException ex) { System.out.println(ex.getMessage()); }

public class SectionProblemLog { public static int NUMBER_OF_SECTIONS = 5; /** * default constructor * the log has 5 rows, but each is null */ SectionProblemLog() { } /** * Sets the length of each row of log to the corresponding number from a. * does nothing if a is null. If the length of a is less than 5, it * sets only as many rows for which it has data. If the length of a is * greater than 5, it only creates the five rows * @param a an array holding the number of problems in each section */ SectionProblemLog(int[] a) { if(a != null) { for(int i = 0; i < a.length && i < NUMBER_OF_SECTIONS; i++) { log[i] = new boolean[a[i]]; } } } /** * Sets each row of log to be a copy of the corresponding row from a. * does nothing if a is null. If the length of a is less than 5, it * sets only as many rows for which it has data. If the length of a is * greater than 5, it only creates and sets the five rows * @param a an array holding the log values */ SectionProblemLog(boolean[][] a) { // YOUR CODE GOES HERE if(a!=null){ } } /** * mutator for log * sets the rows of log to be copies of all rows passed in. * missing rows in a should cause the corresponding row of log * to be set to null * @param a an array holding the log values */ final void setLog(boolean[][] a) { if(a != null) { for(int i = 0; i < a.length && i < NUMBER_OF_SECTIONS; i++) { // YOUR CODE GOES HERE } } } /** * * @param complete the boolean to set at the specified section and number * @param row the section in which the problem is located(starting with 1) * @param col the number of the problem (starting with 1) * @throws IndexOutOfBoundsException if problem not in the log array */ public void setCompleted(boolean complete, int row, int col) throws IndexOutOfBoundsException { // YOUR CODE GOES HERE } /** * * @param row the section in which the problem is located(starting with 1) * @param col the number of the problem (starting with 1) * @return was the col problem in section row completed? * @throws IndexOutOfBoundsException if problem not in the log array */ public boolean getCompleted(int row, int col) throws IndexOutOfBoundsException { // YOUR CODE GOES HERE } /** * accessor for log * @return a copy of the log */ public boolean[][] getLog() { // YOUR CODE GOES HERE } /** * * @param section the number of the section (from 1 to 5) * @return number correct in the specified section * @throws IndexOutOfBoundsException if section not in the log array */ public int numberCorrectInSection(int section) throws IndexOutOfBoundsException { int total = 0; if(log[section - 1] != null) { for(boolean item: log[section - 1]) if(item) total++; } return total; } /** * String version of the log * @return the array as a string */ @Override public String toString() { String mark = "_"; String result = ""; for(int i = 0; i < NUMBER_OF_SECTIONS && log[i] != null; i++) { // YOUR CODE GOES HERE } return result; } private final boolean[][] log = new boolean[NUMBER_OF_SECTIONS][]; }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!