CIT 590 Assignment 10: Sudoku
Spring 2009, David Matuszek
In a Sudoku puzzle, you are given a 9x9 grid, divided into nine 3x3 "boxes," as shown on the right. Some of these boxes have digits in them. The puzzle is to fill in the rest of the grid so that every row, every column, and every 3x3 box contains the digits 1 through 9.Your assignment is to write a program to let a user solve Sudoku puzzles. The user should be able to:
You do not need to make up your own Sudoku puzzlesyou can find lots of them on the web. Your program does not need to solve the puzzles, but it does have to be able to check whether the user has solved the puzzle. 

The GUI will display a 9x9 grid of TextFields,
along with all the controls necessary to allow the user to load, enter, or
solve puzzles. It will also have an int[9][9]
array,
corresponding to the 81 TextFields, that it uses to communicate with the
SudokuModel
object.
You only need one GUI, but it should be clear from looking at the GUI whether the user should be entering a puzzle, or trying to solve one.
Each time the user types something into a TextField (whether the user is entering a puzzle, or trying to solve one), the field should turn red if the entry is illegal (either it isn't a blank or a digit 1..9, or it's a digit but there's a conflict with some other digit).
Write a class SudokuModel
with at least the following methods,
and a JUnit test method (at least one) for each one.
public SudokuModel(int[][] anArray)
 The constructor for your
SudokuModel
class should be given access to theint[9][9]
array in theSudoku
class.public int[][] getBox(int boxRow, int boxColumn)
 Returns a 3x3 array representing a "box" of the 9x9 array. The parameters
boxRow
andboxColumn
are in the range 0 to 2, since there are three rows and three columns of "boxes."public boolean occursInRow(int digit, int row)
 Returns true if the given
digit
(which must be 1..9) occurs in the givenrow
(rows are 0..8), and false otherwise.public boolean occursInColumn(int digit, int column)
 Returns
true
if the givendigit
(which must be 1..9) occurs in the givencolumn
(columns are 0..8), andfalse
otherwise.public boolean occursInBox(int digit, int row, int column)
 Returns
true
if the givendigit
(which must be 1..9) occurs in the box containing the location at the givenrow
andcolumn
of the 9x9 array, andfalse
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.public boolean occursInBox(int digit, int[][] box)
 Returns
true
if the givendigit
(which must be 1..9) occurs in the given 3x3 box, andfalse
otherwise.public boolean isLegalDigit(int digit, int row, int column)
 Returns
true
if the givendigit
(which must be 1..9) does not occur in the givenrow
, or in the givencolumn
, or in the box containing thisrow
andcolumn
, andfalse
otherwise. That is, this digit is a possible candidate for putting in this location; there may be other candidates.public boolean isSolved()
 Returns
true
if the puzzle is complete and correctly solved.
There is some redundancy in the methods, and you might not use them all. That's OK; write them all and test them all, but use what you need.
Remember the DRY principle, and Don't Repeat Yourself. If one method can make
use of another method in order to avoid duplicating code, it should do so.
Feel free to add any additional methods you like; any additional methods should
either be private
, or should have a JUnit test..
Sudoku
sudoku
class Sudoku extends JFrame
class SudokuModel
Sudoku_yourName_partnersName
The above are requirements. You may have additional classes and methods as needed, and they should be documented and unit tested as appropriate.
Thursday, March 9, before midnight. Zip up all files and turn in one copy for your team via Blackboard.