Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

soduku link : https://sudoku.game/ data1.sdk : 2..1.5..3 .54...71. .1.2.3.8. 6.28.73.4 ......... 1.53.98.6 .2.7.1.6. .81...24. 7..4.2..1 Over the first few Long Weekly Homework assignments for this

image text in transcribedimage text in transcribedimage text in transcribed

soduku link :

https://sudoku.game/

data1.sdk :

2..1.5..3 .54...71. .1.2.3.8. 6.28.73.4 ......... 1.53.98.6 .2.7.1.6. .81...24. 7..4.2..1
Over the first few Long Weekly Homework assignments for this quarter, we will build a Sudoku solver program in pieces. This first week we will write code that imports an incomplete sudoku puzzle from a file and prints the board to the screen in a particular way. This is all that we will do this week for the first assignment in this three part Sudoku series. Next week we will add in more methods to determine if the sudoku board is valid and another method to determine if the board is solved. The week after that we will generate code that auto-solves the Sudoku puzzle. Topics 2D arrays, reading from a file, creating a class (fields, constructors, toString) Rules of Sudoku Sudoku puzzles [play online] begin with a 9x9 board where each "cell" is a number (1-9) or an empty space. The goal of the puzzle is to make it so that - every row contains the values 1-9 only once per row, - every column contains the values 1-9 only once per column, and - each of the inside 33 squares only contains the values 1-9 once per small square. The puzzle is solved once all the cells are filled with a number following the rules of the puzzle. For this week's assignment we aren't worried about following the rules of the puzzle or solving the puzzle, but we will be setting up for doing those things eventually. For this week you will do Parts 1, 2, and 3, AND 4 below: Part 1: Define a SudokuBoard Class Create a class for your Sudoku board called SudokuBoard.java that you will use in Parts 2 and 3 below of this week's HW assignment. In Part 4 below you will create an additional Java class with a main method to use for testing out your SudokuBoard class.. Your SudokuBoard class should have: - a single field: a 2D array that will store the contents of the Sudoku board. - You determine the data type stored in the 2D array. You can choose whatever type you want, but it probably makes the most sense to choose either 'int' or 'char'. See the next bullet to help you decide which you want to pick, there is no best choice. - Note that in Sudoku the contents of each "cell" is either a number (1-9) or empty. In the .sdk file that you will read in for Part 2 of this assignment, "empty" cells are represented as a period (.) in the input file. In your 2D array, you do not have to use a period to represent empty - you could use a space char ( ' '), or a star ( '"'), or even the int number zero (0). This is your choice, you just need to be consistent and you need to know what you chose :-) - a constructor for this class that takes one String parameter - you will implement this in Part 2 below, for now just put in the method header - a toString() method - you will implement this in Part 3 below, for now just put in the method header Part 2: Reading in a board data file The next thing that we want to be able to do is load a starting state of a Sudoku board into our class. We will use a made up plain text data file extension which we call .sdk format. Inside a data1.sdk file we might have something that looks like this: 2..1.5.3.5471..1.2.3.8.6.28.73.41.53.98.6.2.7.1.6.81247.4.2.1 You should modify your constructor header to take a file pathame as a String parameter and then load the data from the file into your 2D array. This will look different depending on the data type choice that you made for your 2D array. - Note that for some cells you have a number while in others you have a period - consider how to handle this. - Note that a well-formed .sdk input file will always have nine rows, and each row will have exactly 9 characters, which are digits 1-9 or a period. Part 3: Printing the Board Add a toString() method to your class that will allow you to print the board to the screen. You choose the format of how this looks - I encourage you to make it "pretty" rather than just printing the data to the screen in a grid, but ultimately this decision is up to you. Part 4: Test your Sudoku functionality To verify that the constructor and the toString method your wrote in parts 2 and 3 work, you will need to create another class file (you can name it whatever you want i.e. PlaySudoku.java) with a main method that uses the constructor you wrote to create an object of your SudokuBoard class given a file path as a parameter, and then prints the resulting object to the screen. This file will be incredibly short as the only things inside the main are 1. instantiating an object of your class (calling the constructor that takes as a parameter a String containing the name of the file to load) and then 2. a println that prints that object to the screen (implicitly invoking the toString() method)

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Master The Art Of Data Storytelling With Visualizations

Authors: Alexander N Donovan

1st Edition

B0CNMD9QRD, 979-8867864248

More Books

Students also viewed these Databases questions

Question

9. Understand the phenomenon of code switching and interlanguage.

Answered: 1 week ago