Starting Out with Java: From Control Structures through Data Structures (4th Edition) (What's New in Computer Science)
4th Edition
ISBN: 9780134787961
Author: Tony Gaddis, Godfrey Muganda
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 Data Structures (4th 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 - Prob. 1MCCh. 7 - Prob. 2MCCh. 7 - Prob. 3MCCh. 7 - Prob. 4MCCh. 7 - Array bounds checking happens. a. when the program...Ch. 7 - Prob. 6MCCh. 7 - Prob. 7MCCh. 7 - Prob. 8MCCh. 7 - Prob. 9MCCh. 7 - Prob. 10MCCh. 7 - Prob. 11MCCh. 7 - To delete an item from an ArrayList object, you...Ch. 7 - Prob. 13MCCh. 7 - Prob. 14TFCh. 7 - Prob. 15TFCh. 7 - Prob. 16TFCh. 7 - Prob. 17TFCh. 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 - Prob. 1AWCh. 7 - Prob. 2AWCh. 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 - 12.1994 Gas Prices In the student sample programs...Ch. 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_forwardLab Activity for the students: Exercise 5: Write a program that asks the user to input 8 numbers and save them in a 2D array with 4 rows and 2 columns. The program finds the sum of all elements and prints the array in reverse order. (1 Mark ) Example : If the inputs are 12, 7, 23, 86, 40, 64, 97, 55. Then, the program will print: 55 97 64 40 86 23 7 12 Sum = 384arrow_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_forward
- in C#, Visual Basic Write an app for Boston Airlines that allows a customer to reserve a seat on the airline’s only plane (capacity: 10 seats). Radio buttons should allow the choice between First Class and Economy. The app should then assign a seat in the first-class section (seats 1–5) or the economy section (seats 6–10). Use a one-dimensional array of type bool to represent the seating chart of the plane. Initialize all the elements of the array to false to indicate that all the seats are empty. As each seat is assigned, set the corresponding element of the array to true to indicate that the seat is no longer available. Your app should never assign a seat that has already been assigned. When the economy section is full, your app should ask the person if it is acceptable to be placed in the first-class section (and vice versa). If yes, make the appropriate seat assignment. If no, display the message “Next flight leaves in 3 hours."arrow_forward1. Shift Left k Cells Use Python Consider an array named source. Write a method/function named shiftLeft( source, k) that shifts 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] shiftLeft(source,3) After calling shiftLeft(source,3), printing the array should give the output as: [ 40, 50, 60, 0, 0, 0 ]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
- Use 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_forwardPart-A: Consider first ten letters of your name and for each letter encode with an integer number. For example: If “Ahmed Naser” are the first ten letters from your name, then the array of integers will be {0, 7, 12, 4, 3,13,0,18,4,17}. 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 a b c d e f g h i j k l m n o p q r s t u v w x y z Using the created array, demonstrate below sorting algorithms. It is very important that in each demonstration includes all intermediate arrays in obtaining the final sorted output. Bubble Sort Selection Sort Insertion Sort Shell Sort Merge Sort Quick Sortarrow_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
- this is for java see image thank youarrow_forwardName is Hiba Abdullarrow_forwardAssignment 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_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