Question: Your job is to write a program to solve easy Sudoku puzzles. A problem is easy if, at all times, there is at least one
Your job is to write a program to solve "easy" Sudoku puzzles. A problem is "easy" if, at all times, there is at least one location in the grid that has all but one of the nine digits occurring in the same row, column, or box. Additional information on Sudoku can be found at sudoku rules.
The sudoku project has a single class, Sudoku, which has methods to create, solve and print a Sudoku game.
Finish writing the Sudoku class. Do not modify the constructors or the solve method.
1. Read the comments in the source code of the Sudoku class and finish writing the class according to those instructions. Do not change the method headers.

Image 2:

CODE SODUKU CLASS:
/** * A program to solve "easy" Sudoku puzzles. * * @version Nov. 8, 2007, revised January 2016 */ public class Sudoku { private int[][] problem; /** * Creates a 9x9 array of numbers and sets it up as a * Sudoku problem. Zeros in the array indicate places to be filled in. * This method is complete. Do not change this method. */ public Sudoku() { problem = new int[][] { { 0, 0, 4, 0, 0, 0, 0, 6, 7 }, { 3, 0, 0, 4, 7, 0, 0, 0, 5 }, { 1, 5, 0, 8, 2, 0, 0, 0, 3 }, { 0, 0, 6, 0, 0, 0, 0, 3, 1 }, { 8, 0, 2, 1, 0, 5, 6, 0, 4 }, { 4, 1, 0, 0, 0, 0, 9, 0, 0 }, { 7, 0, 0, 0, 8, 0, 0, 4, 6 }, { 6, 0, 0, 0, 1, 2, 0, 0, 0 }, { 9, 3, 0, 0, 0, 0, 7, 1, 0 } }; }
/** * Takes a 9x9 array of numbers and sets it up as a Sudoku problem. * * @param problem The array representing the Sudoku problem. * This method is complete. Do not change this method. */ public Sudoku(int[][] problem) { this.problem = problem; } /** * Solves this Sudoku problem. * This method is complete. Do not change this method. */ public void solve() { if (!solve(0, 0)) { System.out.println("No solution possible!"); } } /** * Recursively solves this Sudoku problem. * This method is complete. Do not change this method. */ private boolean solve(int row, int col) { // Go to next row if at the end if (col >= 9) { ++row; col = 0; } // If all spaces are filled, then the puzzle is solved if (row >= 9) { print(); return true; } // If the space is marked, go to the next one if (0 != problem[row][col]) { return solve(row, col + 1); } else { // Try all possible numbers boolean solved = false; for (int i = 1; i
/** * Returns a 3x3 array representing a "box" of the 9x9 array. * The parameters boxRow and boxColumn are in the range 0 to 2, * since there are three rows and three columns of "boxes." * * @param boxRow The row number, 0, 1, or 2. * @param boxColumn The column number, 0, 1, or 2. * @return The 3x3 array representing a "box" of the 9x9 array. */ public int[][] getBox(int boxRow, int boxColumn) { int[][] box = new int[3][3]; //complete this method return box;
}
/** * Returns true if the given digit (which must be 1..9) occurs * in the given row (rows are 0..8), and false otherwise. * * @param digit The digit to be searched for in the given row. * @param row The row to search. * @return true if the digit is found, otherwise return false. */ public boolean occursInRow(int digit, int row) { //complete this method return false; }
/** * Returns true if the given digit (which must be 1..9) occurs * in the given column (columns are 0..8), and false otherwise. * * @param digit The digit to be searched for in the given column. * @param column The column to search. * @return true if the digit is found, otherwise return false. */ public boolean occursInColumn(int digit, int column) { //complete this method return false; } /** * Returns true if the given digit (which must be 1..9) occurs * in the given 3x3 box, and false otherwise. * * @param digit The digit to search for. * @param box A 3x3 array in in which to search. * @return true if the given digit is found, otherwise return false. */ public boolean occursInBox(int digit, int[][] box) { //complete this method return false; }
/** * Returns true if the given digit (which must be 1..9) occurs in the box * containing the location at the given row and column of the 9x9 array, and * false otherwise. Note that this method is given a row and column in the * complete 9x9 array, but must search for the given digit in the box containing * that (row, column) location. * * @param digit The digit to be searched for in the appropriate box. * @param row A row number in the range 0 to 8. * @param column A column number in the range 0 to 8. * @return true if the given digit is found in the same box * that contains the given row and column, otherwise return false. */ public boolean occursInBox(int digit, int row, int column) { //complete this method return false; }
/** * Returns true if the given digit (which must be 1..9) does not occur in the * given row, or in the given column, or in the box containing this row and * column, and false otherwise. That is, this digit is a possible candidate for * putting in this location; there may be other candidates. * * @param digit The candidate digit. * @param row The row in which we wish to place the digit. * @param column The column in which we wish to place the digit. * @return true if the candidate digit does not already occur * in the same row, or in the same column, or in the same box. */ public boolean isPossibleDigit(int digit, int row, int column) { //complete this method return false; } }
Bluel: Terminal Window - SudokuSolution Options 16..1 12...I
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
