Java : Introduction To Prob...-MyProgrammingLab
Java : Introduction To Prob...-MyProgrammingLab
15th Edition
ISBN: 9780133860771
Author: SAVITCH
Publisher: PEARSON
bartleby

Concept explainers

Question
Book Icon
Chapter 7, Problem 11PP
Program Plan Intro

Sudoku puzzle

Program plan:

  • Include required header files.
  • Define the “SudokuPuzzle” class.
  • Declare the two-dimensional array variables.
  • In the SudokuPuzzle() constructor,
    • Create objects of SudokoPuzzle class.
  • Define the main() method.
    • Create an object for Scanner class.
    • Create an object for SudokoPuzzle class.
    • Call initializePuzzle() method to initialize the puzzle.
    • Display the puzzle values.
    • The while loop executes until the true. If yes,
      • Check whether the input is “q”. If yes, exit the program.
      • Otherwise, check whether the input is “s”. If yes, set the guess value.
      • Otherwise, check whether the input is “g”. If yes, get the allowed values.
      • Otherwise, check whether the input is “c”. If yes, clear the puzzles.
      • Check whether the puzzle value is not valid. If yes, display the error message.
      • Otherwise, check whether the puzzle is full. If yes, display the success message.
  • In the toString() method,
    • Return the puzzle representation.
  • In the addInitial() method,
    • Check whether row and col is in between “0” to “9” and value is in between “1” to “9”. If yes,
      • Set the puzzle values and the square value cannot be changed by puzzle solver.
  • In the addGuess() method,
    • Check whether row and col is in between “0” to “9” and value is in between “1” to “9” and start puzzle with “0”. If yes, set the guess value to puzzle.
  • In the getValueIn() method,
    • Return the value in given square.
  • In the reset() method,
    • Reset the puzzle value to blank.
  • In the isFull() method,
    • Check whether the puzzle is full and then set the flag value as “true”.
  • In the getAllowedValues() method,
    • Display the allowed values for puzzles.
  • In the checkPuzzle() method,
    • Check whether the values in the squares are legal. If yes, return true.
  • In the checkRow() method,
    • Check whether value is appears only once in row. If yes, return true.
  • In the checkCol() method,
    • Check whether value is appears only once in col. If yes, return true.
  • In the checkSub() method,
    • Check whether value is appears only once in 3 by 3 sub-array. If yes, return true.
  • In the initializePuzzle() method,
    • Call addInitial() method to initialize the puzzle to the board configuration example in the text.

Blurred answer
Students have asked these similar questions
Sudoku is a popular logic puzzle that uses a 9 by 9 array of squares that are organized into 3 by 3 subarrays. The puzzle solver must fill in the squares with the digits 1 to 9 such that no digit is repeated in any row, any column, or any of the nine 3 by 3 subgroups of squares. Initially, some squares are filled in already and cannot be changed. For example, the following might be a starting configuration for a Sudoku puzzle: Create a class SudokuPuzzle.java Download SudokuPuzzle.java that has the attributes • board—a 9 by 9 array of integers that represents the current state of the puzzle, where 0 indicates a blank square • start—a 9 by 9 array of boolean values that indicates which squares in board are given values that cannot be changed and the following methods: • SudokuPuzzle—a constructor that creates an empty puzzle • toString—returns a string representation of the puzzle that can be printed • addInitial(row, col, value)—sets the given square to the given value as an…
Knight's Tour: The Knight's Tour is a mathematical problem involving a knight on a chessboard. The knight is placed on the empty board and, moving according to the rules of chess, must visit each square exactly once. There are several billion solutions to the problem, of which about 122,000,000 have the knight finishing on the same square on which it begins. When this occurs the tour is said to be closed. Your assignment is to write a program that gives a solution to the Knight's Tour problem recursively. You must hand in a solution in C++ AND Java. The name of the C++ file should be "main.cc" and the name of the Java file should be "Main.java". Write C++ only with a file name of main.cc Please run in IDE and check to ensure that there are no errors occuring Output should look similar to: 1 34 3 18 49 32 13 16 4 19 56 33 14 17 50 31 57 2 35 48 55 52 15 12 20 5 60 53 36 47 30 51 41 58 37 46 61 54 11 26 6 21 42 59 38 27 64 29 43 40 23 8 45 62 25 10 22 7 44 39 24 9 28 63
JAVA - Multi Dimensional Arrays Ask the user for the number of rows and columns of a two-dimensional array and then its integer elements. Print the row number of the row where the sum of all of its elements is even.   For this problem, it is guaranteed that there is one and only one row of such case. Row count starts at 0. Input 1. One line containing an integer for the number of rows 2. One line containing an integer for the number of columns 3. Multiple lines containing at least one integer each line for the elements of the array Sample 2 7 4 1 1 2 0 5 0 Output Note that the row number starts at 0, not 1. Enter # of rows: 3 Enter # of columns: 3 Enter elements: 2 7 4 1 1 2 0 5 0 Even row: 1

Chapter 7 Solutions

Java : Introduction To Prob...-MyProgrammingLab

Ch. 7.2 - Give the definition of a static method called...Ch. 7.2 - Prob. 12STQCh. 7.2 - The following method compiles and executes but...Ch. 7.2 - Suppose that we add the following method to the...Ch. 7.3 - Prob. 15STQCh. 7.3 - Replace the last loop in Listing 7.8 with a loop...Ch. 7.3 - Suppose a is an array of values of type double....Ch. 7.3 - Suppose a is an array of values of type double...Ch. 7.3 - Prob. 19STQCh. 7.3 - Consider the partially filled array a from...Ch. 7.3 - Repeat the previous question, but this time assume...Ch. 7.3 - Write an accessor method getEntryArray for the...Ch. 7.4 - Prob. 23STQCh. 7.4 - Write the invocation of the method selectionSort...Ch. 7.4 - How would you need to change the method...Ch. 7.4 - How would you need to change the method...Ch. 7.4 - Consider an array b of int values in which a value...Ch. 7.5 - What output is produced by the following code?...Ch. 7.5 - Revise the method showTable in Listing 7.13 so...Ch. 7.5 - Write code that will fill the following array a...Ch. 7.5 - Write a void method called display such that the...Ch. 7.6 - Prob. 33STQCh. 7 - Write a program in a class NumberAboveAverage that...Ch. 7 - Write a program in a class CountFamiles that...Ch. 7 - Write a program in a class CountPoor that counts...Ch. 7 - Write a program in a class FlowerCounter that...Ch. 7 - Write a program in a class characterFrequency that...Ch. 7 - Create a class Ledger that will record the sales...Ch. 7 - Define the following methods for the class Ledger,...Ch. 7 - Write a static method isStrictlyIncreasing (double...Ch. 7 - Write a static method removeDuplicates(Character[]...Ch. 7 - Write a static method remove {int v, int [] in}...Ch. 7 - Suppose that we are selling boxes of candy for a...Ch. 7 - Create a class polynomial that is used to evaluate...Ch. 7 - Write a method beyond LastEntry (position) for the...Ch. 7 - Revise the class OneWayNoRepeatsList, as given in...Ch. 7 - Write a static method for selection sort that will...Ch. 7 - Overload the method selectionSort in Listing 7.10...Ch. 7 - Revise the method selectionSort that appears in...Ch. 7 - Prob. 18ECh. 7 - Write a sequential search of an array of integers,...Ch. 7 - Write a static method findFigure (picture,...Ch. 7 - Write a static method blur (double [] [] picture)...Ch. 7 - Write a program that reads integers, one per line,...Ch. 7 - The following code creates a small phone book. An...Ch. 7 - Write the method rotateRight that takes an array...Ch. 7 - The following code creates a ragged 2D array. The...Ch. 7 - Write a program that will read a line of text that...Ch. 7 - Prob. 2PPCh. 7 - Add a method bubbleSort to the class ArraySorter,...Ch. 7 - Add a method insertionSort to the class...Ch. 7 - The class TimeBook in Listing 7.14 is not really...Ch. 7 - Define a class called TicTacToe. An object of type...Ch. 7 - Repeat Programming Project 10 from Chapter 5 but...Ch. 7 - Prob. 8PPCh. 7 - Write a GUI application that displays a picture of...Ch. 7 - ELIZA was a program written in 1966 that parodied...Ch. 7 - Prob. 11PPCh. 7 - Create a GUI application that draws the following...Ch. 7 - Practice Program 2 used two arrays to implement a...Ch. 7 - Practice Program 5.4 asked you to define Trivia...
Knowledge Booster
Background pattern image
Computer Science
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
SEE MORE QUESTIONS
Recommended textbooks for you
Text book image
Database System Concepts
Computer Science
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:McGraw-Hill Education
Text book image
Starting Out with Python (4th Edition)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON
Text book image
Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON
Text book image
C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON
Text book image
Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning
Text book image
Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education