Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Overview Over the first few Long Weekly Homework assignments for this quarter, we will build a Sudoku e solver program in pieces. The first step
Overview Over the first few Long Weekly Homework assignments for this quarter, we will build a Sudoku e solver program in pieces. The first step is to 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 for the first assignment in the Sudoku series; we will later add in testing to make sure the rules of Sudoku are followed and after that 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 e puzzles [play online 2 ] 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 3x3 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 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. Instructions 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 of this HW assignment. 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 you want, but it probably makes the most sense to choose either 'int' or 'char". See the next bullet to help you decide which to pick. 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 (), or a star (*), or even the int number zero (O). 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 for now just put in the method header a toString() method you will implement this in Part 3 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 .54...71. .1.2.3.8. 6.28.73.4 1.53.98.6 .2.7.1.6 .81...24. 7..4.2..1 You should modify your constructor header to take a file pathame as a 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 test that everything works, you will need to create another class file (you can name it whatever you want i.e. PlaySudoku.java) with a main method that creates an object of your SudokuBoard class given a file path 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 the file to load) and then 2. a println that prints to object to the screen (implicitly invoking the toString() method)
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started