Java: An Introduction to Problem Solving and Programming (8th Edition)
Java: An Introduction to Problem Solving and Programming (8th Edition)
8th Edition
ISBN: 9780134462035
Author: Walter 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
An 8-puzzle game consists of 8 sliding tiles, numbered by digits from 1 to 8 and arranged in a 3x3 array of nine cells.  A configuration in the puzzle refers to some specific arrangement of the tiles in the array, where each digit is arranged into a different cell. One of the cell is empty (represented by a "*") and any adjacent tile can be moved into the empty cell. An example below     c   | 1 | 2 | 3  b   | 4 | * | 5  a   | 6 | 7 | 8------------------ Y/X    a   b   c We use a 3-tuple (number, X, Y) to represent the position of a digit, where number is the actual digit, and (X,Y) is the coordinate value of the digit in the current configuration (e.g., in the configuration above, we have (5,c,b), meaning the digit 5 is at the position of (c,b)).Hence the configuration in the example can be represented as:[(1,a,c), (2,b,c), (3,c,c), (4,a,b), (5,c,b), (6,a,a), (7,b,a), (8,c,a)].Any move of an adjacent tile into the empty cell moves the current configuration into the one adjacent to it.…
Query Board              Python or Java(Preferred Python please) Thank you! Programming challenge description: There is a board (matrix). Every cell of the board contains one integer, which is 0 initially.The following operations can be applied to the Query Board:SetRow i x: change all values in the cells on row "i" to value "x".SetCol j x: change all values in the cells on column "j" to value "x".QueryRow i: output the sum of values on row "i".QueryCol j: output the sum of values on column "j".The board's dimensions are 256x256."i" and "j" are integers from 0 to 255."x" is an integer from 0 to 31. Input: Your program should read lines from standard input. Each line contains one of the above operations. Output: For each query, output the result of the query. Test 1 Test InputDownload Test 1 Input SetCol 32 20 SetRow 15 7 SetRow 16 31 QueryCol 32 SetCol 2 14 QueryRow 10 Expected OutputDownload Test 1 Input 5118 34
A Hide Time Remaining A Geometric Progression Printer As you might recall, a Geometric Progression (or GP) is a sequence of elements in which the next number in the sequence is obtained by multiplying the previous number by the common ratio. The next number in the sequence is obtained by using this formula: a_n=a_1*r(n-1) While the sum of all numbers in the sequence is obtained using any of these formulae: If r= 1, sum=a*n Ifr != 1 and r> 1, sum = a[(rª-1)/(r - 1)] Ifr != 1 and r < 1, sum = a[(1-r)/(1-r)] where a_n = next number in the sequence, a_1 = first number in the sequence, r = common ratio, n = number of terms Your task is to write a Python program that 1: Accepts the necessary inputs from the user, i.e., start value (a_1), common ratio (r), and number of generate to generate (n). 2. Generates the Geometric Progression (GP) sequence starting from a_1 to n. 3. Prints out the GP HORIZONTALLY not VERTICALLY, e.g. 3, 9, 27, 81, 243, 729.... 4. Calculates the sum of all numbers in…

Chapter 7 Solutions

Java: An Introduction to Problem Solving and Programming (8th Edition)

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.6 - Prob. 34STQCh. 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 - A palindrome is a word or phrase that reads the...Ch. 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
C++ Programming: From Problem Analysis to Program...
Computer Science
ISBN:9781337102087
Author:D. S. Malik
Publisher:Cengage Learning