Java: An Introduction to Problem Solving and Programming (7th Edition)
7th Edition
ISBN: 9780133766264
Author: Walter Savitch
Publisher: PEARSON
expand_more
expand_more
format_list_bulleted
Concept explainers
Question
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.
- Check whether row and col is in between “0” to “9” and value is in between “1” to “9”. If yes,
- 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.
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents 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.…
C++ language
Write a program that asks the user to enter daily sale for five stores and record them in an array.The program should then display a bar graph comparing each store’s sales for all days of a week.Create each bar in the bar graph by displaying a row of asterisks. Each asterisk should representRs.1000 of sales. The program also calculates the total sale each day, and total sale of the week.Here is an example of the program s output.Enter day 1 sales for store 1: 4000 [Enter]Enter day 1 sales for store 2: 6000 [Enter]Enter day 1 sales for store 3: 10000 [Enter]Enter day 1 sales for store 4: 11000 [Enter] Enter day 1 sales for store 5: 3000 [Enter]Enter day 2 sales for store 1: 9000 [Enter]Enter day 2 sales for store 2: 8000 [Enter]Enter day 2 sales for store 3: 19000 [Enter]Enter day 2 sales for store 4: 7000 [Enter]Enter day 2 sales for store 5: 9000 [Enter]…(and so on.)Weekly SaleMonday: Total Sale: 34,000/-Store 1: **** (4000)Store 2: ****** (6000)Store 3: **********…
please code in python
You place a pawn at the top left corner of an n-by-n chess board, labeled (0,0). For each move, you have a choice: move the pawn down a single space, or move the pawn down one space and right one space. That is, if the pawn is at position (i,j), you can move the pawn to (i+1,j) or (i+1, j+1).
Ask the user for the size of a chessboard, n (integer). Find the number of different paths starting from (0,0) that the pawn could take to reach each position on the chess board. For example, there are two different paths the pawn can take to reach (2,1). Look at the diagrams below to convince yourself of this. You can see the four paths that you can take by move 2.
Start -> Move 1 -> Move 2
(0,0) -> (1,0) -> (2,1)
(0,0) -> (1,0) -> (2,0)
(0,0) -> (1,1) -> (2,1)
(0,0) -> (1,1) -> (2,2)
Print the board with the number of ways to reach each square labeled as shown below.
For example:
Enter a board size: 4
1 0 0 0
1 1 0 0
1 2 1 0
1 3 3 1
Chapter 7 Solutions
Java: An Introduction to Problem Solving and Programming (7th Edition)
Ch. 7.1 - What output will be produced by the following...Ch. 7.1 - What output will be produced by the following...Ch. 7.1 - What output will be produced by the following...Ch. 7.1 - Consider the following array: int [] a = new...Ch. 7.1 - What is wrong with the following code to...Ch. 7.1 - Write a complete Java program that reads 20 values...Ch. 7.2 - Write some Java code that will declare an array...Ch. 7.2 - Rewrite the method displayResults of the program...Ch. 7.2 - What output will be produced by the following...Ch. 7.2 - Give the definition of a static method called...
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
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
- Tic-Tac-Toe Problem Description: Tic Tac Toe game is traditionally played on a 3x3 board berween two players x and o. A player can mark a single cell by placing a symbol in it (either an 'x'or an 'o' character). A player who manages to mark a row, column, or a diagonal completely with his symbol first wins the game. The game ends in a tie if no player manages to win after all the cells have been marked. You will design a textual version of this game, in which a human player gets to play against a computer opponent. Program Specification: In this project, you will implement a complete Tie-Tac-Toe game in a Java program. Your implementation should follow this specification. You may use one or two dimensional amay as data structure for the game board. Your program should include the following list ef methods: 1. initBoard ()- update this method This function initializes the game board. There are 9 cells represented by I or 2 dimensional armay. 2. gameBoard ()- upcdate this method This…arrow_forwardProgramming Language: C++ You have been hired by Google to work on their YouTube videos search team. Every YouTube video has a unique ID and those IDs are in unsorted order. As a software engineer, you are required to make a YouTube search engine which works for very user. Create a test engine that only holds seven YouTube IDs. Prompt for and get from the user the seven IDs and store them in an integer array. Then sort and print the array using the insertion sort algorithm. Finally, use a sentinel loop to prompt for and get from the user a series of IDs. For each ID, perform a binary search on the array and tell the user if it was found or not. If found, print the index where the ID is stored. Continue to prompt the user for an ID until entering the sentinel value of -999. In addition to function main, define the following two functions: void insertion_sort(int arr[], int arr_size) int binary_search(int sort_arr[], int size_array, int search_value) binary_seacrh returns…arrow_forwardBeeblebrox question help requiredarrow_forward
- The program should be written in C languagearrow_forwardCodeWorkout Gym Course Q Search kola shreya@ columbusstate.edu Search exercises... X274: Recursion Programming Exercise: Cannonballs X274: Recursion Programming Exercise: Cannonballs Spherical objects, such as cannonballs, can be stacked to form a pyramid with one cannonball at the top, sitting on top of a square composed of four cannonballs, sitting on top of a square composed of nine. cannonballs, and so forth. Given the following recursive function signature, write a recursive function that takes as its argument the height of a pyramid of cannonballs and returns the number of cannonballs it contains. Examples: cannonball(2) -> 5 Your Answwer: 1 public int cannonball(int height) { 3. 4} Check my answer! Reset Next exercise Feedbackarrow_forwardIn visual basic Write a For…Next loop that will printout each value in the array from problem 4.arrow_forward
- please help me step by step solve all option and please add the output screen please thank you againarrow_forwardObjectives Java refresher (including file I/O) Use recursion Description For this project, you get to write a maze solver. A maze is a two dimensional array of chars. Walls are represented as '#'s and ' ' are empty squares. The maze entrance is always in the first row, second column (and will always be an empty square). There will be zero or more exits along the outside perimeter. To be considered an exit, it must be reachable from the entrance. The entrance is not an exit.Here are some example mazes:mazeA 7 9 # # ##### # # # # # # # ### # # # # ##### # # # ######### mazeB 7 12 # ########## # # # # # # # #### # # # # # # ##### ## # # # # ############ mazeC 3 5 # # # ## ## Requirements Write a MazeSolver class in Java. This program needs to prompt the user for a maze filename and then explore the maze. Display how many exits were found and the positions (not indices) of the valid exits. Your program can display the…arrow_forwarduse C++ programming language A local zoo wants to keep track of how many pounds of food each of its three monkeys eats each day during a typical week. Write a program that stores this information in a two-dimensional 3×7 array, where each row represents a different monkey and each column represents a different day of the week. The program should first have the user input the data for each monkey. Then it should create a report that includes the following information: Average amount of food eaten per day by the whole family of monkeys The least amount of food eaten during the week by any one monkey The greatest amount of food eaten during the week by any one monkey.arrow_forward
- C Program Removing Elements in an Array Make a program that creates an array by asking the size n of the array and n integer inputs. Example: Input size of array: 5 Array elements: 1 2 3 4 5 After creating the array, you need to prompt the user again to pick m number of elements to remove. If the input is invalid, prompt the user to try again. An input is invalid if it meets either one of these criteria: Greater than size n of the array Negative number Example: Number of elements to remove: -2 Invalid number. Try again: 3 After a valid input, prompt the user for the valid indices to remove. An index is valid if it is within the range of the array size. Output the array elements after a valid index input and consider the new size of the array after. Example: Index (1): 2 Array elements: 1 2 4 5 Index (2): 4 Invalid index! Try again. Index (2): 0 Array elements: 2 4 5 Index (3): 2 Array elements: 2 4 After everything, print FINISHED! Input 1. Size of array 2.…arrow_forwardCredit card numbers follow certain patterns: It must have between 13 and 16 digits, and the number must start with:■ 4 for Visa cards■ 5 for MasterCard credit cards■ 37 for American Express cards■ 6 for Discover cards In 1954, Hans Luhn of IBM proposed an algorithm for validating credit card numbers. The algorithm is useful to determine whether a card number is entered correctly or whether a credit card is scanned correctly by a scanner. Credit card numbers are generated following this validity check, commonly known as the Luhn check or the Mod 10 check, which can be described as follows (for illustration, consider the card number 4388576018402626): 1. Double every second digit from right to left. If doubling of a digit results in a two-digit number, add up the two digits to get a single-digit number. 2. Now add all single-digit numbers from Step 1. 3. Add all digits in the odd places from right to left in the card number. 4. Sum the results from Steps 2 and 3. 5. If the result from…arrow_forwardcode itarrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- C++ Programming: From Problem Analysis to Program...Computer ScienceISBN:9781337102087Author:D. S. MalikPublisher:Cengage Learning
C++ Programming: From Problem Analysis to Program...
Computer Science
ISBN:9781337102087
Author:D. S. Malik
Publisher:Cengage Learning