Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

At the beginning of the program, briefly describe to the user what a Magic Square Matrix is (described further on), and then allow them to

At the beginning of the program, briefly describe to the user what a Magic Square Matrix is (described further on), and then allow them to enter start to begin the earch. The goal of this program is to output a matrix with all rows, columns and diagonals having the same sum this is called the Magic Square Matrix. The maximum digit in the matrix should not exceed 9 and all numbers in the matrix are UNIQUE (meaning that each number does not appear more than once in the matrix). You will keep generating matrices and outputting whether it is a Magic Square Matrix or not. Once you output a Magic Square Matrix, the program will exit.

You must have the following methods created and used within your program: 1. sumRows(int [][]array) The method will calculate the sum of the rows in your generated matrix. Return the sum of rows if they are all equal else return -1 if they are not equal. Hint: sum of all elements/number of rows= sum of rows. If all row sums are equal. 2. sumColumns(int [][]array)The method will calculate the sum of the columns in your generated matrix. Return the sum of columns if they are all equal else return -1 if they are not equal. 3. sumDiagonals(int [][]array) The method will calculate the sum of the diagonals in your generated matrix and will return the sum of the diagonals if they are all equal, else return -1 if they are not equal. Hint: Diagonals indexes are: - Diagonal 1: [0][0],[1][1], [2][2] - Diagonal 2: [size-1][0], [size-2][1] [0][2] 4. isUnique(int [][] array, int num) Checks if num exists in the array. If num exists in the array, return false. If it does not exist in the array, return true. 5. displayMagicSquare(int [][] array) Prints the two-dimensional Array. 6. fillMatrix(int [][] array) Fills the two dimensional Array with Unique random numbers from 1 9 And returns the array. 7. isMagicSquare(int [][]array) returns true only if: - The array has sum of its rows equal to its columns and equal to its diagonals - Rows, columns, and diagonals sums are above 0.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions