Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

here is Debugging.java : public class Debugging{ public static void setHints(int[][] array){ //Iterate over every element in our 2D Array for(int i = 0; i

image text in transcribed

here is Debugging.java :

public class Debugging{ public static void setHints(int[][] array){ //Iterate over every element in our 2D Array for(int i = 0; i = anArray.length) { toReturn = false; } //Else, check if the column is greater than or equal to the length of the row in the array. (Besides causing an array out of bounds // exception, we check these two separately so that if the rowIndex is out of bounds, we don't try and use it to get a column because THAT // would cause an array out of bounds exception as well) else if(columnIndex >= anArray[rowIndex].length) { toReturn = false; } //Else check if the element at the given index is equal to -1. else if(anArray[rowIndex][columnIndex] == -1) { toReturn = false; } //Return our result. If none of the above conditions are met, this should return true. If any of the above conditions are met, //this should return false return toReturn; } } 

-----------------------------------

here is DebuggingTests.java :

import static org.junit.Assert.*; import org.junit.Test; public class DebuggingTest { @Test public void testSetHintNumbersOneMine() { int[][] actual = { { 0, 0, 0, 0, 0, 0 }, { 0, 0, 0, 0, 0, 0 }, { 0, 0, -1, 0, 0, 0 }, { 0, 0, 0, 0, 0, 0 }, { 0, 0, 0, 0, 0, 0 }, { 0, 0, 0, 0, 0, 0 } }; int[][] expected = { { 0, 0, 0, 0, 0, 0 }, { 0, 1, 1, 1, 0, 0 }, { 0, 1, -1, 1, 0, 0 }, { 0, 1, 1, 1, 0, 0 }, { 0, 0, 0, 0, 0, 0 }, { 0, 0, 0, 0, 0, 0 } }; Debugging.setHints( actual ); assertArrayEquals( "Incorrect result", expected, actual ); } @Test public void testSetHintNumbersTwoMinesAwayFromThemselvesAndBoundaries() { int[][] array = { { 0, 0, 0, 0, 0, 0 }, { 0, -1, 0, 0, 0, 0 }, { 0, 0, 0, 0, 0, 0 }, { 0, 0, 0, 0, 0, 0 }, { 0, 0, 0, 0, -1, 0 }, { 0, 0, 0, 0, 0, 0 } }; int[][] expected = { { 1, 1, 1, 0, 0, 0 }, { 1, -1, 1, 0, 0, 0 }, { 1, 1, 1, 0, 0, 0 }, { 0, 0, 0, 1, 1, 1 }, { 0, 0, 0, 1, -1, 1 }, { 0, 0, 0, 1, 1, 1 } }; Debugging.setHints( array ); assertArrayEquals( "Incorrect result", expected, array ); } @Test public void testSetHintNumbersThreeMinesCloseToThemselvesAndBoundaries() { int[][] array = { { 0, -1, 0, 0, 0, 0 }, { 0, 0, 0, 0, 0, 0 }, { -1, 0, 0, 0, 0, 0 }, { -1, 0, 0, 0, 0, 0 }, { 0, 0, 0, 0, 0, 0 }, { 0, 0, 0, 0, 0, 0 } }; int[][] expected = { { 1, -1, 1, 0, 0, 0 }, { 2, 2, 1, 0, 0, 0 }, { -1, 2, 0, 0, 0, 0 }, { -1, 2, 0, 0, 0, 0 }, { 1, 1, 0, 0, 0, 0 }, { 0, 0, 0, 0, 0, 0 } }; Debugging.setHints( array ); assertArrayEquals( "Incorrect result", expected, array ); } @Test public void testSetHintNumbersSeveralMines() { int[][] array = { { -1, 0, 0, 0, 0, -1 }, { 0, 0, 0, 0, 0, 0 }, { 0, 0, -1, -1, 0, 0 }, { 0, 0, -1, -1, 0, 0 }, { 0, 0, 0, 0, 0, 0 }, { -1, 0, 0, 0, 0, -1 } }; int[][] expected = { { -1, 1, 0, 0, 1, -1 }, { 1, 2, 2, 2, 2, 1 }, { 0, 2, -1, -1, 2, 0 }, { 0, 2, -1, -1, 2, 0 }, { 1, 2, 2, 2, 2, 1 }, { -1, 1, 0, 0, 1, -1 } }; Debugging.setHints( array ); assertArrayEquals( "Incorrect result", expected, array ); } } 

From Blackboard, download Debugging.java and DebuggingTests.java. Debugging.java is a java program which solves the following problem: 1) Write to class "Debugging", a method "setHints" (below) that accepts a 2 dimensional array of integers containing - 1s and 0s and modifies it according to the following (minesweeper) criteria: to hint of its presence, for each mine (a value - 1) increment by 1 the value of all its surrounding squares; if another mine exists in one of these squares, its value is left public static void setHints (int[] [ array) i //Your code here The figure below illustrates the state of an array at the beginning of the method (left) and at the end of the method (right) after all the hint values have been added. 1 1 0 00 0 0 0 1 1 2 1 0 0 2 13 1 0 0 2 13 1 Rather, the provided debugging class attempts to solve the problem. When you run the test cases, you will notice none of them pass. Debugging.java contains three bugs within its source code preventing the correct answer from being achieved. The objective of this lab is to use the debugger provided in Eclipse along with the information provided by the test cases to detect and correct these errors. When you discover and correct an error, you must insert a comment describing the error and what you did to correct the error. When you have corrected all the bugs in Debugging.java and all of the given test cases pass, upload your corrected Debugging.java file to blackboard Note: you MUST correct the provided Debugging.java class. You cannot create your own solution to the given problem. No points will be given to any custom made submissions. Also, none of the corrections to Debugging.java require drastic modifications to the program. If yoiu find yourself deleting /rewriting large swaths of code, take a pause and revaluate your debugging strategy From Blackboard, download Debugging.java and DebuggingTests.java. Debugging.java is a java program which solves the following problem: 1) Write to class "Debugging", a method "setHints" (below) that accepts a 2 dimensional array of integers containing - 1s and 0s and modifies it according to the following (minesweeper) criteria: to hint of its presence, for each mine (a value - 1) increment by 1 the value of all its surrounding squares; if another mine exists in one of these squares, its value is left public static void setHints (int[] [ array) i //Your code here The figure below illustrates the state of an array at the beginning of the method (left) and at the end of the method (right) after all the hint values have been added. 1 1 0 00 0 0 0 1 1 2 1 0 0 2 13 1 0 0 2 13 1 Rather, the provided debugging class attempts to solve the problem. When you run the test cases, you will notice none of them pass. Debugging.java contains three bugs within its source code preventing the correct answer from being achieved. The objective of this lab is to use the debugger provided in Eclipse along with the information provided by the test cases to detect and correct these errors. When you discover and correct an error, you must insert a comment describing the error and what you did to correct the error. When you have corrected all the bugs in Debugging.java and all of the given test cases pass, upload your corrected Debugging.java file to blackboard Note: you MUST correct the provided Debugging.java class. You cannot create your own solution to the given problem. No points will be given to any custom made submissions. Also, none of the corrections to Debugging.java require drastic modifications to the program. If yoiu find yourself deleting /rewriting large swaths of code, take a pause and revaluate your debugging strategy

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Managing Your Information How To Design And Create A Textual Database On Your Microcomputer

Authors: Tenopir, Carol, Lundeen, Gerald

1st Edition

1555700233, 9781555700232

More Books

Students also viewed these Databases questions

Question

Explain the concept of psychological disengagement.

Answered: 1 week ago