Ask Question, Ask an Expert

+61-413 786 465

info@mywordsolution.com

Ask Java Expert


Home >> Java

SudCell and Simple Sudoku Implementation

We describe, fully, the SudCell class that will represent each of the 81 cells or boxes in a Sudoku puzzle.  Then we will see a simple version of the Sudoku class.  Make sure you have read and understood the general introduction to the SudCell and Sudoku class in the main assignment page.  I have laid out every detail of the class members and methods for you, so although this is a long document, it should be actually easier than assignments which are shorter but less specific.

SudCell Class Specification

 Create a class called SudCell that has the following private members:

  • boolean digits[] - an array of nine booleans, each representing the digits 1 through 9.  If digits[0] is true, that means this cell might contain a 1.  If digits[1] is true, it might contain a 2, and so on.  This is private.
  • boolean completed - a private boolean telling our higher level classes whether or not we are done exploiting this cell.  All SudCell objects start with completed = false, even those for which we are given the final value, because for those "givens" we still have not utilized that fact yet.  Once we do, we turn this cell off (set completed to true).

The following public static members will allow us to turn this into a 4x4 or  16x16 Sudoku with a few keystrokes -- we'll use these constants throughout the code and never have a 1 through 9 literal in any part of our program.

  • static final int MIN_VAL = 1
  • static final int MAX_VAL = 9
  • static final int NUM_VALS = 9
  • static final int SQRT_NUM_VALS = 3
  • static final int NOT_FINAL_YET = -1    (used to signal whether or not we have narrowed down the boolean digits[] array to one value -- different from completed if you think about it).

You should supply all of the following public methods (at a minimum):

Basic Stuff:

  • Constructor - just one, default, that allocates digits[], sets the digits to all true and completed to false.
  • ToString() - a method that will return a String that is a " - " if the cell has more than one true, or a digit (surrounded by spaces) if the cell is narrowed down to just one (true) value. Since the Sudoku class will  need to build a 9x9 matrix on the display, this should not contain any newline ('\n') character -- just three chars, the two spaces and the middle digit or '-'.  This is used for end-user output.
  • ToStringReveal() - This returns a string that contains all the values that this cell might still be.  In other words, if you have not ruled out 3, 5 or 9, it would return the string " 359 " (with spaces at both ends).  If you have narrowed it down to 9, it will return " 9 ".  If you have not narrowed it down at all, it would return " 123456789 ".   (I could have combined ToString() and ToStringReveal() into one method that took a boolean parameter, but I chose to make these two different methods.)  In a console based application, printing all the cells using ToStringReveal() might result in a raggedy matrix, since each cell will have a different length, but that's not too critical.  You could make the return values of ToStringReveal() all the same length by padding with spaces, but from two weeks of debugging I have found that it is better to let the 9x9 array that displays these "revealed" strings be jagged, because it helps to more easily determine whether two successive outputs of an in-progress Sudoku are the same or different.

 

Java, Programming

  • Category:- Java
  • Reference No.:- M9522382

Have any Question?


Related Questions in Java

Assignment - java program using array of objectsobjectives

Assignment - JAVA Program using array of objects Objectives - This assessment item relates to the course learning outcomes as stated in the Unit Profile. Details - For this assignment, you are required to develop a Menu ...

Assessment socket programmingtaskwrite a java gui program

Assessment: Socket Programming Task Write a JAVA GUI program that would facilitate text chatting/exchanging between two or multiple computers over the network/internet, using the concept of JAVA socket programming. If yo ...

Can someone help me please with those question1what is the

Can someone help me please with those question 1:what is the best data type for student id datatime,currency,number,decimal 2:which relationshipis preferable? one to one,one to many,many to many 3:if you add table A's pr ...

Project descriptionwrite a java program to traverse a

Project Description: Write a java program to traverse a directory structure (DirWalker.java) of csv files that contain csv files with customer info. A simple sample in provided in with the sample code but you MUST will r ...

Operating systems assignment -problem 1 sharing the bridgea

Operating Systems Assignment - Problem 1: Sharing the Bridge A new single lane bridge is constructed to connect the North Island of New Zealand to the South Island of New Zealand. Farmers from each island use the bridge ...

Can someone please help me with the following java

can someone please help me with the following java question The input is an N by N matrix of nonnegative integers. Each individual row is a decreasing sequence from left to right. Each individual column is a decreasing s ...

Applied software engineering assignment 1 -learning

Applied Software Engineering Assignment 1 - Learning outcomes - 1. Understand the notion of software engineering and why it is important. 2. Analyse the risk factors associated with phases of the software development lif ...

Can someone kindly help me to consider whether java

Can someone kindly help me to consider whether Java provides the facility of operator overloading? If it does, may you kindly describe how overloading operators can be accomplished? If not, may you kindly describe why yo ...

Assessment -java program using array of Assessment -JAVA Program using array of objects

Assessment -JAVA Program using array of objects Objectives This assessment item relates to the course learning outcomes as stated in the Unit Profile. Details For this assignment, you are required to develop a Windowed G ...

Assignment game prototypeoverviewfor this assessment task

Assignment: Game Prototype Overview For this assessment task you are expected to construct a prototype level/area as a "proof of concept" for the game that you have designed in Assignment 1. The prototype should function ...

  • 4,153,160 Questions Asked
  • 13,132 Experts
  • 2,558,936 Questions Answered

Ask Experts for help!!

Looking for Assignment Help?

Start excelling in your Courses, Get help with Assignment

Write us your full requirement for evaluation and you will receive response within 20 minutes turnaround time.

Ask Now Help with Problems, Get a Best Answer

Why might a bank avoid the use of interest rate swaps even

Why might a bank avoid the use of interest rate swaps, even when the institution is exposed to significant interest rate

Describe the difference between zero coupon bonds and

Describe the difference between zero coupon bonds and coupon bonds. Under what conditions will a coupon bond sell at a p

Compute the present value of an annuity of 880 per year

Compute the present value of an annuity of $ 880 per year for 16 years, given a discount rate of 6 percent per annum. As

Compute the present value of an 1150 payment made in ten

Compute the present value of an $1,150 payment made in ten years when the discount rate is 12 percent. (Do not round int

Compute the present value of an annuity of 699 per year

Compute the present value of an annuity of $ 699 per year for 19 years, given a discount rate of 6 percent per annum. As