QuestionQuestion

You are to write a program that will solve sudoku puzzles. To learn about sudoku, you can visit the wikipedia page. All you really need to read, though, is the first paragraph where the rules are explained and then look at the example on the right..
You must implement the two classes with the methods shown below and use them to solve the puzzles.
Do not make any changes to the classes, variables, names, etc. Just add code! Also, no backtracking or recursion should be used. This assignment is as much about following instructions as it is about programming. Be sure your methods do exactly what is expected of them.

class Spot {
private int row, col;

public Spot(int row, int col) {
public void setRow(int row) {
public void setCol(int col) {
public int getRow() {
public int getCol() {

class sudoku {
private int board[][];

// default constructor -- I never seem to use it....
public sudoku() {

// Construct a new sudoku puzzle from a string
// This piece of code might be useful to you:
// (int) (s[row].charAt(col + col/3)) - 48
public sudoku(String s[]) {

// Copy constructor
public sudoku(sudoku p) {

// Hint: use String.valueOf( i ) to convert an int to a String
public String toString() {

// for easy checking of your answers
public String toString2() {
String result = new String();
for (int row = 0; row < 9; row++) {
for (int col = 0; col < 9; col++) {
result = result + String.valueOf(board[row][col]);
}
}
return result;
}

// create rotated sudoku puzzle – used by my test programs
public void rotate() {
int[][] temp = new int[9][9]; int row, col;
for (row = 0; row < 9; row++) {
for (col = 0; col < 9; col++) { temp[col][8-row] = board[row][col];
}
}
for (row = 0; row < 9; row++) {
for (col = 0; col < 9; col++) { board[row][col] = temp[row][col];
}
}
}

// Does the current board satisfy all the sudoku rules?
public boolean isValid() {

// Is this a solved sudoku?
public boolean isComplete() {

// return true if val appears in the row of the puzzle
private boolean doesRowContain(int row, int val) {

// return true if val appears in the col (column) of the puzzle
private boolean doesColContain(int col, int val) {

// return true if val appears in the 3 x 3 box
private boolean doesBoxContain(int col, int val) {

// return n if n is the only possible value for this spot
// return 0 otherwise
private int fillSpot(Spot sq) {

// return a valid spot if only one possibility for val in row
// return null otherwise
private Spot rowFill(int row, int val) {

// return a valid spot if only one possibility for val in col
// return null otherwise
private Spot colFill(int col, int val) {

// return a valid spot if only one possibility for val in the box
// return null otherwise
private Spot boxFill(int rowbox, int colbox, int val) {

public void solve() {

// who are you? Put your name here!
public static String myName() {
return "John Q. Smith";
}

Solution PreviewSolution Preview

These solutions may offer step-by-step problem-solving explanations or good writing examples that include modern styles of formatting and construction of bibliographies out of text citations and references. Students may use these solutions for personal skill-building and practice. Unethical use is strictly forbidden.

// Spot class represents the row, col
// position in the board
class Spot {
    private int row, col;

    public Spot(int row, int col) {
       setRow(row);
       setCol(col);
    }

    public void setRow(int row) {
       this.row = row;
    }

    public void setCol(int col) {
       this.col = col;
    }

    public int getRow() {
       return this.row;
    }

    public int getCol() {
       return this.col;
    }
}

/**
* sudoku class containing methods to solve
* the given sudoku problem
*/
class sudoku {

    // 2-D array of integers representing board game.
    private int board[][];

    // default constructor -- I never seem to use it....
    public sudoku() {
       board = new int[9][9];
    }

    // Construct a new sudoku puzzle from a string
    // This piece of code might be useful to you:
    // (int) (s[row].charAt(col + col/3)) - 48
    public sudoku(String s[]){
       board = new int[9][9];
       for(int i=0; i<9; i++){
            board[i] = new int[9];
            for(int j=0; j<9; j++){
                board[i][j] = (int) (s[i].charAt(j + j/3)) - 48;
            }
       }
    }

    // Copy constructor
    public sudoku(sudoku p) {
       int[][] b = p.board;
       for(int i=0; i<9; i++){
            for(int j=0; j<9; j++){
                board[i][j] = b[i][j];
            }
       }
    }...

By purchasing this solution you'll be able to access the following files:
Solution.java.

50% discount

Hours
Minutes
Seconds
$50.00 $25.00
for this solution

or FREE if you
register a new account!

PayPal, G Pay, ApplePay, Amazon Pay, and all major credit cards accepted.

Find A Tutor

View available Java Programming Tutors

Get College Homework Help.

Are you sure you don't want to upload any files?

Fast tutor response requires as much info as possible.

Decision:
Upload a file
Continue without uploading

SUBMIT YOUR HOMEWORK
We couldn't find that subject.
Please select the best match from the list below.

We'll send you an email right away. If it's not in your inbox, check your spam folder.

  • 1
  • 2
  • 3
Live Chats