Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

This is a bonus project of 5%. Please do it only when you have time to complete

ID: 3844988 • Letter: T

Question

This is a bonus project of 5%. Please do it only when you have time to complete it. Please write a Java application program that can check a Sudoku game and show its result in detail. This is an application of a 2-dimensioinal array. The following is a sample test, which must be all your test cases. As you can see, you must pre-load the following 4 games into 4 arrays (for example, S1, S2, S3, and S4) in your program. Welcome to play the game of Sudoku! Your game 1 is as follows: 123456789 234567891 345678912 456789123 567891234 678912345 789123456 891234567 912345678 Square 1 has a problem. Square 2 has a problem. Square 3 has a problem. Square 4 has a problem. Square 5 has a problem. Square 6 has a problem. Square 7 has a problem. Square 8 has a problem. Square 9 has a problem. Your game 2 is as follows: 123456789 456789123 789123456 234567891 567891234 891234567 345678912 678912345 912345678 Congratulations! You won the game. Your game 3 is as follows: 123456782 456789123 789123456 234567891 567891234 891234567 345678912 678912345 912345678 Row 1 has a problem. Column 9 has a problem. Square 3 has a problem. Your game 4 is as follows: 123456789 456789123 789123456 234567891 567891234 891234567 345678912 678918345 912345678 Row 8 has a problem. Column 6 has a problem. Square 8 has a problem. Thank you for playing this Sudoku game! Hope to see you again!

Explanation / Answer

Introduction

Sudoku game follows the below rules:

1 An integer may only appear once in

2.A game has only one solution.

IMPLEMENTATION

Here we are using the SudokuChecker class in which the funtionality of this class is:

PROGRAM:

public class SudokuChecker {

static int[][] sMatrix=new int[9][9];

int a,b;

System.out.println("Enter the sudoku solution ");

for(a=0;a<9;a++)

{

for(b=0;b<9;b++)

{

System.out.println(sMatrix[a][b]);

}

}

static int rSum=0;

static int cSum=0;

static int[] rSumArray=new int[9];

static int[] cSumArray=new int[9];

static int[] boxSumArray=new int[9];

static boolean checkArrayStatus(int[] rSumArray,int[] cSumArray,int[] boxSumArray)

{

int i=0;

boolean sudokuStatus=true;

System.out.println("/n Congratulations!You won the game");

while(i<9){

        if(rSumArray[i]!=45)

        {  

            sudukoStatus=false;

            System.out.println("Row %d has a problem");

            break;

        }

        else if(cSumArray[i]!=45)

        {  

            sudukoStatus=false;

            System.out.println("Column %d has a problem");

            break;

        }

        i++;

        else(rSumArray[i]!=45)

        {

            sudukoStatus=false;

            System.out.println("Square %d has a problem");

            break;

        }

    }

    return sudukoStatus;

}  

    public static void main(String[] args) {

        for(int i=0 ; i<sMatrix.length ; i++){

            for(int j=0 ; j<sMatrix.length ; j++){

                rSum+=sMatrix[i][j];

                cSum+=sMatrix[j][i];

                }

            rSumArray[i]=rSum;

            cSumArray[i]=cSum;

            rSum=0;

            cSum=0;

        }

        for(int i=0 ; i< sMatrix.length ; i++){

            for(int j=0 ; j<sMatrix.length ; j++){

                if(i<=2&&j<=2)

                {

                    boxSumArray[0]+=sMatrix[i][j];

                }

                if(i<=2&&(j>=3&&j<=5))

                {

                    boxSumArray[1]+=sMatrix[i][j];

                }

                if(i<=2&&(j>=6&&j<=8))

                {

                    boxSumArray[2]+=sMatrix[i][j];

                }

                if((i>=3&&i<=5)&&(j<=2))

                {

                    boxSumArray[3]+=sMatrix[i][j];

                }

                if((i>=3&&i<=5)&&(j>=3&&j<=5))

                {

                    boxSumArray[4]+=sMatrix[i][j];

                }

                if((i>=3&&i<=5)&&(j>=6&&j<=8))

                {

                    boxSumArray[5]+=sMatrix[i][j];

                }

                if((i>=6)&&(j<=2))

                {

                    boxSumArray[6]+=sMatrix[i][j];

                }

                if((i>=6)&&(j>=3&&j<=5))

                {

                    boxSumArray[7]+=sMatrix[i][j];

                }

                if((i>=6)&&(j>=6))

                {

                    boxSumArray[8]+=sMatrix[i][j];

                }

            }

        }

        if(checkArrayStatus(rSumArray,cSumArray,boxSumArray))

        {

            System.out.println("The matrix is sudoku compliant");

        }

        else

        {

            System.out.println("The matrix is not sudoku compliant");

        }

    }

}

EXPECTED OUTPUT

Input

Enter the sudoku solution

123456789

456789123

789123456

234567891

567891234

891234567

345678912

678912345

912345678

Output:

Congratulations!You won the game!

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote