Question: Activity 3. Magic Squares. In this activity, you will be given a 2D array of integers (acquired within the main: code is provided to you),

Activity 3. Magic Squares. In this activity, you will be given a 2D array of integers (acquired within the main: code is provided to you), and you have to check if this 2D array (table or matrix as you prefer) is a magic square. What is a magic square? A magic square is a square 2D array or table or matrix, which has the following properties: the numbers in each row, column, and diagonal (main and secondary) add up to the same value. So for instance, the following table is a magic square: Method MagicSquare Parameter: a 2D array of integers Return type: Boolean This method returns true if the parameter is a magic square, false otherwise. Requirement: The implementation of this method requires the implementation of four auxiliary methods: sumRow, sumColumn, sumDiagonal1, and sumDiagonal2. Method sumRow Parameters: A 2D array of integers; and An integer i Return type: integer This method returns the sum of the numbers in the ith row of the 2D array. Requirement: You are expected to use a for loop to implement this method. Method sumColumn Parameters: A 2D array of integers; and An integer i Return type: integer This method returns the sum of the numbers in the ith column of the 2D array. Requirement: You are expected to use a for loop to implement this method. Method sumDiagonal1 Parameters: a 2D array of integers Return type: integer This method returns the sum of the numbers in the main diagonal of the 2D array. Requirement: You are expected to use a for loop to implement this method. Method sumDiagonal2 Parameters: a 2D array of integers Return type: integer This method returns the sum of the numbers in the secondary diagonal of the 2D array. Requirement: You are expected to use a for loop to implement this method. Instructions: 1. Write the pseudocode for method MagicSquare in a docx file named yourLastName-yourFirstName-lab7.docx: this pseudocode should call the auxiliary methods sumRow, sumColumn, sumDiagonal1, and sumDiagonal2. No need for pseudocode for the auxiliary methods. 2. Modify the code provided in Lab7Spring16.java where prompted (and only where prompted) to make sure that the code follows the above instructions. Note: inability to follow instructions will be penalized by 10 points. Now, here is what you have to turn in: 1. The modified java file called Lab7Spring16.java. 2. The file yourLastName-yourFirstName-lab7.docxin which you have described your pseudocode (= your algorithm).

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!