Starting Out with Java: From Control Structures through Objects (7th Edition) (What's New in Computer Science)
7th Edition
ISBN: 9780134802213
Author: Tony Gaddis
Publisher: PEARSON
expand_more
expand_more
format_list_bulleted
Question
Chapter 7, Problem 20PC
Program Plan Intro
Lo Shu Magic Square
Program Plan:
- Import the required packages.
- Declare the class “Main”.
- Declare the “main ()” method.
- Declare two 2-Dimensional arrays.
- Call the function “show_Array ()” to display the array.
- Call the function “show_Result ()” to display the result.
- Give function definition for “show_Result ()”.
- Check if the square is a magic square by calling the function “isMagicSquare ()”.
- If yes, then print the positive message.
- Else,
- Print the negative message.
- Check if the square is a magic square by calling the function “isMagicSquare ()”.
- Give function definition for “show_Array ()” to display the array.
- Using nested “for” loops, print the values of the array.
- Give function definition for “isMagicSquare ()”.
- Declare a Boolean variable.
- Call the function “check_Range ()”, “checkUnique ()”, “checkRowSum ()”, “check_ColSum ()”, and “check_DiagSum ()”.
- Check the condition “is_InRange && is_Unique && is_EqualRows &&is_EqualCols && is_EqualDiag”.
- Assign “true” to the Boolean variable.
- Return the variable.
- Give function definition for “check_Range ()”.
- Declare required variables.
- Using nested “for” loops, check the condition “array[row][col] < MIN || array[row][col] > MAX”.
- Assign “false” to the Boolean variable.
- Return the variable.
- Give function definition for “check_Unique ()”.
- Declare required variables.
- Using the while condition “searchValue <= MAX && status == true”.
- Using nested “for” loops,
- Check the condition “array[row][col] == searchValue”,
- Increment the counter variable.
- Check if count value is greater than 1.
- Assign “false” to the Boolean variable.
- Check the condition “array[row][col] == searchValue”,
- Increment the variable “searchValue”.
- Assign 0 to the counter variable.
- Using nested “for” loops,
- Return the status.
- Give function definition for “check_RowSum ()”.
- Declare a variable.
- Calculate the sum of 1st row, 2nd row and 3rd row.
- Check if all the values are not equal to each other.
- Assign “false” to the Boolean variable.
- Return the variable.
- Give function definition for “check_ColSum ()”.
- Declare a variable.
- Calculate the sum of 1st column, 2nd column and 3rd column.
- Check if all the values are not equal to each other.
- Assign “false” to the Boolean variable.
- Return the variable.
- Give function definition for “check_DiagSum ()”.
- Declare a variable.
- Calculate the sum of 1st diagonal, and 2nd diagonal.
- Check if all the values are not equal to each other.
- Assign “false” to the Boolean variable.
- Return the variable.
- Declare the “main ()” method.
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
GetMonth - This method prompts for and returns the month GetNumMurals - This method prompts for and returns the number of murals scheduled and is called twice -- once for interior murals and once for exterior murals ComputeRevenue - This method accepts the number of interior and exterior murals scheduled, accepts the month they are scheduled, displays the interior and exterior prices, and then returns the total expected revenue DataEntry - This method fills an array with customer names and mural codes and is called twice -- once to fill the array of interior murals and once to fill the array of exterior murals GetSelectedMurals - This method continuously prompts for mural codes and displays jobs of the corresponding type until a sentinel value is entered. In order to prepend the $ to currency values, the program will need to use the CultureInfo.GetCultureInfo method.
in C#
A positive integer greater than 1 is said to be prime if it has no divisors other than 1 and itself. Write a program that asks the user to input an integer greater than 1, then display all of the prime numbers that less than or equal to the number entered. The program should work as follows:
• Once the user has entered a number, the program should display an array with all of the integers from 2 up through the value entered.
• The program should then use a loop to step through the array. The loop should pass each element to a method that displays the element whether it is prime number.
Your result should look like, for example:
Enter an integer greater than 1: 9
2, 3, 4, 5, 6, 7, 8, 9
2 is prime
3 is prime
4 is not prime
5 is prime
6 is not prime
7 is prime
8 is not prime
9 is not prime
Using java programming
In this project you will generate a poker hand containing five cards randomly selected from a deck of cards. The names of the cards are stored in a text string will be converted into an array. The array will be randomly sorted to "shuffle" the deck. Each time the user clicks a Deal button, the last five cards of the array will be removed, reducing the size of the deck size. When the size of the deck drops to zero, a new randomly sorted deck will be generated. A preview of the completed project with a randomly generated hand is shown in Figure 7-50.
Chapter 7 Solutions
Starting Out with Java: From Control Structures through Objects (7th Edition) (What's New in Computer Science)
Ch. 7.1 - Write statements that create the following arrays:...Ch. 7.1 - Whats wrong with the following array declarations?...Ch. 7.1 - Prob. 7.3CPCh. 7.1 - Prob. 7.4CPCh. 7.1 - Prob. 7.5CPCh. 7.1 - Prob. 7.6CPCh. 7.1 - Prob. 7.7CPCh. 7.1 - Prob. 7.8CPCh. 7.2 - Prob. 7.9CPCh. 7.2 - Prob. 7.10CP
Ch. 7.2 - A program has the following declaration: double[]...Ch. 7.2 - Look at the following statements: int[] a = { 1,...Ch. 7.3 - Prob. 7.13CPCh. 7.3 - Write a method named zero, which accepts an int...Ch. 7.6 - Prob. 7.15CPCh. 7.7 - Recall that we discussed a Rectangle class in...Ch. 7.10 - Prob. 7.17CPCh. 7.11 - What value in an array does the selection sort...Ch. 7.11 - How many times will the selection sort swap the...Ch. 7.11 - Prob. 7.20CPCh. 7.11 - Prob. 7.21CPCh. 7.11 - If a sequential search is performed on an array,...Ch. 7.13 - What import statement must you include in your...Ch. 7.13 - Write a statement that creates an ArrayList object...Ch. 7.13 - Write a statement that creates an ArrayList object...Ch. 7.13 - Prob. 7.26CPCh. 7.13 - Prob. 7.27CPCh. 7.13 - Prob. 7.28CPCh. 7.13 - Prob. 7.29CPCh. 7.13 - Prob. 7.30CPCh. 7.13 - Prob. 7.31CPCh. 7 - In an array declaration, this indicates the number...Ch. 7 - Each element of an array is accessed by a number...Ch. 7 - The first subscript in an array is always. a. 1 b....Ch. 7 - The last subscript in an array is always. a. 100...Ch. 7 - Array bounds checking happens. a. when the program...Ch. 7 - This array field holds the number of elements that...Ch. 7 - Prob. 7MCCh. 7 - This search algorithm repeatedly divides the...Ch. 7 - Prob. 9MCCh. 7 - When initializing a two-dimensional array, you...Ch. 7 - Prob. 11MCCh. 7 - To delete an item from an ArrayList object, you...Ch. 7 - To determine the number of items stored in an...Ch. 7 - True or False: java does not allow a statement to...Ch. 7 - True or False: An arrays sitze declarator can be a...Ch. 7 - Prob. 16TFCh. 7 - True or False: The subscript of the last element...Ch. 7 - Prob. 18TFCh. 7 - True or False: The Java compiler does not display...Ch. 7 - Prob. 20TFCh. 7 - True or False: The first size declarator in the...Ch. 7 - Prob. 22TFCh. 7 - Prob. 23TFCh. 7 - int[] collection = new int[-20];Ch. 7 - Prob. 2FTECh. 7 - Prob. 3FTECh. 7 - Prob. 4FTECh. 7 - Prob. 5FTECh. 7 - The variable names references an integer array...Ch. 7 - The variables numberArray1 and numberArray2...Ch. 7 - Prob. 3AWCh. 7 - In a program you need to store the populations of...Ch. 7 - In a program you need to store the identification...Ch. 7 - Prob. 6AWCh. 7 - Prob. 7AWCh. 7 - Prob. 8AWCh. 7 - Prob. 9AWCh. 7 - Prob. 10AWCh. 7 - Prob. 11AWCh. 7 - Prob. 1SACh. 7 - Prob. 2SACh. 7 - Prob. 3SACh. 7 - Prob. 4SACh. 7 - Prob. 5SACh. 7 - Prob. 6SACh. 7 - Prob. 7SACh. 7 - Prob. 8SACh. 7 - Prob. 9SACh. 7 - Rainfall Class Write a RainFall class that stores...Ch. 7 - Payroll Class Write a Payroll class that uses the...Ch. 7 - Charge Account Validation Create a class with a...Ch. 7 - Charge Account Modification Modify the charge...Ch. 7 - Prob. 5PCCh. 7 - Drivers License Exam The local Drivers License...Ch. 7 - Magic 8 Ball Write a program that simulates a...Ch. 7 - Grade Book A teacher has five students who have...Ch. 7 - Grade Book Modification Modify the grade book...Ch. 7 - Average Steps Taken A Personal Fitness Tracker is...Ch. 7 - Array Operations Write a program with an array...Ch. 7 - Prob. 12PCCh. 7 - Sorted List of 1994 Gas Prices Note: This...Ch. 7 - Name Search If you have downloaded this books...Ch. 7 - Population Data If you have downloaded this books...Ch. 7 - World Series Champions If you have downloaded this...Ch. 7 - 2D Array Operations Write a program that creates a...Ch. 7 - Prob. 18PCCh. 7 - Trivia Game In this programming challenge, you...Ch. 7 - Prob. 20PC
Knowledge Booster
Similar questions
- 2. Rotate Left k cells Use Python Consider an array named source. Write a method/function named rotateLeft( source, k) that rotates all the elements of the source array to the left by 'k' positions. You must execute the method by passing an array and number of cells to be shifted. After calling the method, print the array to show whether the elements have been shifted properly. Example: source=[10,20,30,40,50,60] rotateLeft(source,3) After calling rotateLeft(source,3), printing the array should give the output as: [ 40, 50, 60, 10, 20, 30]arrow_forwardJumping in the Mega Millions fever, your lab is to write a program that simulates the Mega Millions lottery draw. Your program must have an array of five integers named winningNumbers, with a randomly generated number in the range of 0 through 9 for each element in the array. Your program should ask the user to enter five numbers and should store them in a second integer array named player. The program must compare the corresponding elements in the two arrays and count how many numbers match. For example, the following shows the winningNumbers array and the Player array with sample numbers stored in each. There are two matching elements, elements 2 and 4. Once the user has entered a set of numbers, the program should display the winning numbers and the player's numbers and tell how many numbers matched. Here is an example of the possible output from your code: /* SAMPLE RESULTS RUN 1 Submit the five numbers of your lottery number, separated by blanks: 93441 Winning number: 30766 Your…arrow_forwardAn array called number contains 20 integer values and must be filled with values in the following way: Fill the array with consecutive even numbers starting from 10. Start again at the first element and increase every fourth element with 3. Replace the value of the first four elements each with its square. Deduct 2 from the last 3 elements. Swap the value of element 5 and element 15. Add the value of the first element to that of the last element Add consecutive integers (starting from 1) to all even elements.Remember, the first element has a subscript of 0 and the last element (element 20) has a subscript of 19.The following must be displayed: All elements must be displayed each on a new line. Identify each element clearly. Display the highest value in the array. The lowest value in the array must be displayed. Count and display how many even values and how many odd values the array contains.arrow_forward
- A company has 5 stores {1, 2, 3, 4, 5}. The sales for each store is as follows: {200, 300, 400, 500, 600}. The tax rate is 6% Write a java program that: Prints the values in the 2-D array consisting of the store numbers and sales. Your print out should also include the sales tax for each company. In essence, you should have three columns: Store Number, Sales and Sales Taxarrow_forwardUse a one-dimensional array to solve the following problem: A company pays its salespeople on a commission basis. The salespeople receive $200 per week plus 9% of their gross sales for that week. For example, a salesperson who grosses $5000 in sales in a week receives $200 plus 9% of $5000, or a total of $650. Write an application (using an array of counters) that determines how many of the salespeople earned salaries in each of the following ranges (assume that each salesperson’s salary is truncated to an integer amount): $200–299 $300–399 $400–499 $500–599 $600–699 $700–799 $800–899 $900–999 $1000 and over Summarize the results in tabular format.arrow_forwardCreate a class containing the main method. In the main method, create an integer array and initialize it with the numbers: 1,3,5,7,9,11,13,15,17,19 Pass the array as an argument to a method. Use a loop to add 1 to each element of the array and return the array to the main method. In the main method, use a loop to add the array elements and display the result. Note: In the loops, use the array field that holds the length of the array and do not use a number for array length.arrow_forward
- Assignment 5B: Maze Game! 2D Arrays can be used to store and represent information about video game levels or boards. In this exercise, you will use this knowledge to create an interactive game where players attempt to move through a maze. You will start by creating a pre-defined 2D array with the following values: :-, X","X"} "X","W"} "X","_"} "} 'X","X"} {"_" " "y" " " You will then set the player (represented by "O") at index 0, 0 of the array, the top-left corner of the maze. You will use a loop to repeatedly prompt the user to enter a direction ("Left", “Right", “Up", or “Down"). Based on these directions, you will try to move the player. If the location is valid (represented by “_"), you will move the player there If the location is out of bounds (e.g. index 0, -1) or the command is invalid, you will inform the player and prompt them to enter another direction If the location is a wall (represented by “X"), you will tell the user they hit a wall and the game is over. If the…arrow_forwardMulti-Dimensional Arrays Create a multi-dimensional array of size 20 by 20. Create the following methods; • Create Board: This method will create the multi-dimensional array and initialize the values to zeros, such as this; 00000000000000000000 00000000000000000000 00000000000000000000 etc • Place Ship: This method will accept as parameters the starting coordinates of the ship, the type, and the direction. (vertical or horizontal) Then it will place the ship on the board by updating the array values to be dash characters, such as this " - " The ships: One Battleship of length 8 o One destroyer of length 2 o Two cruisers of length 4 each O • Print Board: This method will output the contents of the board. Where there are ships, the dash character will be printed, where there are no ships, the zero character will be printed. • Fire: This method will accept two coordinates from the user. If there is a ship at that location, it will update the value to X for a hit. If there is no ship, it…arrow_forwardC# In your main method use the method in question 1 to display the letters array, then use the Array.Reverse() method to reverse the letters array and then again call the appropriate method to print itarrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- Programming Logic & Design ComprehensiveComputer ScienceISBN:9781337669405Author:FARRELLPublisher:CengageEBK JAVA PROGRAMMINGComputer ScienceISBN:9781337671385Author:FARRELLPublisher:CENGAGE LEARNING - CONSIGNMENT
Programming Logic & Design Comprehensive
Computer Science
ISBN:9781337669405
Author:FARRELL
Publisher:Cengage
EBK JAVA PROGRAMMING
Computer Science
ISBN:9781337671385
Author:FARRELL
Publisher:CENGAGE LEARNING - CONSIGNMENT