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

I\'m in java one and need help with this code. please follow the givne direction

ID: 3695640 • Letter: I

Question

I'm in java one and need help with this code. please follow the givne directions and test your program to make sure it works as it is required. I will apreciate your help. please follostept by step the given directions in the UML DIAGRAM. thank you.

Here are two correct 4x4 Sudoku grids:

  

3

2

4

1

4

1

3

2

1

4

2

3

2

3

1

4

4x4 Sudoku Example #1

1

2

3

4

3

4

1

2

2

1

4

3

4

3

2

1

4x4 Sudoku Example #2

Notice how each row, column and region has the individual numbers from 1 through 4 used only once. This means that the values used in each row, column and region must add up to 10 (1 + 2 + 3 + 4). This is how we will check our 4x4 Sudoku grids for this assignment.

Allow your user to enter their Sudoku grids row-by-row, separating each of the four values by a space and hitting ENTER at the end of the row.

When the user has entered all 16 values into the program, you should output validation checks for each region, row and column. An example run can be seen below with sample user input underlined.

This program checks simple, small, 4x4 Sudoku grids for correctness. Each column, row and 2x2 region contains the numbers 1 through 4 only once.

To check your Sudoku, enter your board one row at a time, with each digit separated by a space. Hit ENTER at the end of a row.

SUDO:VALID

Your program does not have to check for the numbers 1 through 4 being used uniquely in each row, column and region. In other words, don't worry about validating their input to make sure they only enter the digits 1, 2, 3 or 4 and only enter them once per row, column and region. At this point in the semester, writing data validation like that would be incredibly painful.

You simply need to check that each row, column and region adds up to 10.

This simplistic type of checking will, however, allow some bad Sudoku grids to be validated as good. See two examples of this below. For this program, we will let these instances slide and not worry about them.

4

1

1

4

1

4

4

1

1

4

4

1

4

1

1

4

Invalid 4x4 Sudoku That Will Be Labeled as valid, Example #1

10

0

0

0

0

0

10

0

0

10

0

0

0

0

0

10

Invalid 4x4 Sudoku That Will Be Labeled as valid, Example #2

Rows, columns and regions are identified as found below:

ROW1

ROW2

ROW3

ROW4

C

O

L

1

C

O

L

2

C

O

L

3

C

O

L

4

REGION

1

REGION

3

REGION

2

REGUON

4

When producing your output, you must first validate the regions, then the rows and then the columns. Each region, row and column validation should appear on a line by itself using the identifiers REG-1, REG-2, REG-3, REG-4, ROW-1, ROW-2, ROW-3, ROW-4, COL-1, COL-2, COL-3, and COL-4.

Each identifier will be followed immediately by a colon and that colon will be followed immediately by the word GOOD or the word BAD depending on if that row/column/region passes or fails validation.

The final line of output should be the keyword SUDO, followed immediately by a colon, followed immediately by either the word VALID or the word INVALID.

Please see the example run and run the sample program a number of times to make sure you understand how output is expected to be displayed for this program.

UML DIAGRAM FOR CLASS NetID_SudokuChecker
Create a class based on your UNO NetID. Replace NetID in the following example with your UNO NetID.

«constructor» NetID_SudokuChecker ( )

+ displayGrid ( )
+ getGrid ( )
+ checkGrid ( )

DISCUSSION OF CLASS NetID_SudokuChekcer
What follows is a short description of what each data member represents and what each method does:

grid

grid is a private data member that is a 4x4 array of integers. It will store the four rows of four items in each row.

This is the constructor. It should display welcome greetings, explaining the rules of the 4x4 Sudoku grid we're processing.

getGrid()

This public method should read the Sudoku grid from the user row by row, using spaces between values in each row.

This public method simply displays the grid to the screen in a nice, square pattern.

This public method uses the private data member grid to test whether or not the given values are a valid Sudoku grid.

Your method does not have to check for the numbers 1 through 4 being used uniquely in each row, column and region. In other words, don't worry about validating their input to make sure they only enter the digits 1, 2, 3 or 4 and only enter them once per row, column and region. You can add this functionality, but it is not required.

When producing your output, you must first validate the regions, then the rows and then the columns. Each region, row and column validation should appear on a line by itself using the identifiers REG-1, REG-2, REG-3, REG-4, ROW-1, ROW-2, ROW-3, ROW-4, COL-1, COL-2, COL-3, and COL-4.

Each identifier will be followed immediately by a colon and that colon will be followed immediately by the word GOOD or the word BAD depending on if that row/column/region passes or fails validation.

The final line of output should be the keyword SUDO, followed immediately by a colon, followed immediately by either the word VALID or the word INVALID.

Make sure your spelling and formatting for each of the above is correct.

DISCUSSION OF THE FILE NetID_SudokuChecker.java
You will need to implement your class methods in the file NetID_SudokuChecker.java. This file should follow the basic outline here:

import java.util.Scanner;
public class NetID_SudokuChecker {

A MAIN / TEST PROGRAM (NetID_SudokuCheckerTest.java)

To test your implementation of the NetID_SudokuChecker class, use the following code for NetID_SudokuCheckerTest.java,changing NetID to your UNO NetID.

public class NetID_SudokuCheckerTest

{

public static void main ( String args[] )

{

NetID_SudokuChecker sudChecker = new NetID_SudokuChecker();

}

}

SUMMARY OF FILES

You will need to create two files for this assignment:

. NetID_SudokuChecker.java, which will be modeled after the code example seen at the top of this page.

. NetID_SudokuCheckerTest.java, which will contain the code exactly as seen above.

Essentially, you will type in the code exactly as seen in this assignment for both files. You will then plug in the appropriate code into the methods of the NetID_SudokuChecker.java file.

DO NOT CHANGE THE NAMES OF ANY OF THE methods OR THE CLASS ITSELF!!!!!

Goals

Implement a moderately straightforward class that creates three methods (a constructor and two other methods) to implement a Sudoku- checking data type using a UML specification as a guideline for creation of the class.

Points to Think About

Try compiling your class often, after adding maybe five or ten lines of code to your program. By doing this, you’re less likely to have dozens of errors to have to fix after compilation.

You may wish to set up the instance variable and shells for the methods themselves first and compile that code without any real code inside any of the methods. You can also set up the Tester class and try compiling that against your compiled SudokuChecker class.

Then, go back and start filling in code for each of the methods in the SudokuChecker class.

Grading Notes

>> Method documentation is required for all methods other than main()and you must follow the Program Coding Standards handout posted to Blackboard for this course. Points will be deducted for missing or incomplete method documentation.

>> Your methods must behave as outlined in this assignment.

>> Make sure your output follows the format you see in the example solution provided. A portion of your grade is for following this format exactly. If you messed up some of the output on your previous Sudoku solution, now is the time to fix it.

Output Example

Sample Run (user input is underlined)

This program checks simple, small, 4x4 Sudoku grids for correctness. Each column, row and 2x2 region contains the numbers 1 through 4 only once.

To check your Sudoku, enter your board one row at a time, with each digit separated by a space. Hit ENTER at the end of a row.

0 0 0 0

0 0 0 0

0 0 0 0

0 0 0 0

EnterRow1:1 2 3 4

EnterRow2:3 4 2 1

EnterRow3:1 2 3 4

EnterRow4:4 3 2 1

1 2 3 4

3 4 2 1

1 2 3 4

4 3 2 1

Thank you. Now checking ...

sample output run 2

Welcome to the Sudoku Checker v1.0!

This program checks simple, small, 4x4 Sudoku grids for correctness. Each column, row and 2x2 region contains the numbers 1 through 4 only once.

To check your Sudoku, enter your board one row at a time, with each digit separated by a space. Hit ENTER at the end of a row.

0 0 0 0

0 0 0 0

0 0 0 0

0 0 0 0

EnterRow1: 3 2 4 1

EnterRow2: 4 1 3 2

EnterRow3: 1 4 2 3

EnterRow4: 2 3 1 4

3 2 4 1

4 1 3 2

1 4 2 3

2 3 1 4

Thank you. Now checking ...

SUDO:VALID

3

2

4

1

4

1

3

2

1

4

2

3

2

3

1

4

Explanation / Answer

code:

Solution:

NetID_SudokuChecker.java

package NetID_SudokuCheckerTest;

import java.util.Scanner;

public class NetID_SudokuChecker{

private int [][] grid;

public NetID_SudokuChecker(){ //call constructor

     // display intro code

     Scanner inn = new Scanner(System.in);

     final int row = 4;

     final int colom = 4;

     grid = new int[row][colom]; //Declaration of grid array

     System.out.println("Welcome to the Sudoku Checker v1.0!");

     System.out.println(" ");

     System.out.println("This program checks simple, small, 4x4 Sudoku grids for correctness. Each column, row and 2x2 region contains the numbers 1 through 4 only once.");

     System.out.println(" ");

     System.out.println("To check your Sudoku, enter your board one row at a time, with each digit separated by a space. Hit ENTER at the end of a row.");

     System.out.println(" ");

}

//grid method take input from user and enter values into grid array row by row

public void getGrid()

{

     Scanner scanner = new Scanner(System.in);

     for(int r = 0; r < grid.length; r++) //Entering values

     {

          System.out.printf(" Enter Row %d: ", r + 1);

          String[] input = scanner.nextLine().trim().split(" "); //splitting values by space

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

              try{

                        grid[r][i] = Integer.parseInt(input[i]);

              }catch(Exception e){

  

              }

          }

     }

}

public void displayGrid(){

     // Display grid before and after input.

     System.out.println(" ");

     System.out.println("Here is the grid as I see it now:");

     for(int x=0; x<grid.length; x++){

          for(int y=0; y<grid[x].length; y++){

              System.out.print(" "+grid[x][y]);

          }

          System.out.println(" ");

     }

}

public void checkGrid(){

     //Check the given grid is good sudoku or not

     //Checks all reg, col, row add up to 10.

     int row = 0;

     boolean sudo=true;//Initializing variable sudo to zero

     System.out.println(" ");

     System.out.println("Thank you. Now checking...");

     System.out.println(" ");

     for(int x = 0; x < grid.length; x++){

          for(int y =0; y<grid[x].length; y++){

              row += grid[x][y];

          }

     System.out.printf(" ROW-%d:",x);

     if(row!=10){

          sudo=false;

          System.out.printf(" BAD");

     }

     row=0;

     if(sudo==true){

          System.out.print(" GOOD");

     }

     }

     int coll = 0;

     System.out.println(" ");

     for(int y = 0; y < grid.length; y++){

          for(int x = 0; x < grid[y].length; x++){

              coll += grid[x][y];

              System.out.printf(" COL-%d: ",x);

          }

          System.out.printf(" COL-%d:",y);

          if(coll!=10){

              sudo=false;

              System.out.printf(" BAD");

          }

          coll=0;

          if(sudo==true){

              System.out.print(" GOOD");

          }

     }

int reg1=0;

System.out.println(" ");

if(grid[0][0]+grid[0][1]+grid[1][0]+grid[1][1]==10){

System.out.print(" REG-1: GOOD");

}

else{

sudo=false;

System.out.print(" REG-1: BAD");

}

if(grid[0][2]+grid[0][3]+grid[1][2]+grid[1][3]==10){

System.out.print(" REG-3: GOOD");

}

else{

sudo=false;

System.out.print(" REG-3: BAD");

}

if(grid[0][2]+grid[0][3]+grid[1][2]+grid[1][3]==10){

System.out.print(" REG-2: GOOD");

}

else{

sudo=false;

System.out.print(" REG-2: BAD");

}

if(grid[2][2]+grid[2][3]+grid[3][2]+grid[3][3]==10){

System.out.print(" REG-4: GOOD");

}

else{

sudo=false;

System.out.print(" REG-4: BAD");

}

System.out.println(" ");

if(sudo==true){

System.out.print(" SUDO: VALID");

}

else{

System.out.print(" SUDO: INVALID");

}

}

}

NetID_SudokuCheckerTest.java

package NetID_SudokuCheckerTest;

import java.util.Scanner;

//this is pre-defined packege for scanner ...

public class NetID_SudokuCheckerTest{ //class name

public static void main (String args[]){ //main method declaration...

Scanner in = new Scanner(System.in);

//it it to take input from user...

NetID_SudokuChecker foo = new NetID_SudokuChecker();

//Constuctor call

foo.displayGrid(); //calling method in NetID_SudokuChecker to display the default grid with all Zero's in grid...

foo.getGrid();

//this statement calls the method to take input from user...

foo.displayGrid();

//this method displays the grid entered by user...

foo.checkGrid();

//this method checks for the given sudoku is valid or not...

}

}

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