Question: In java, create a java class to complete the Lo Shu Magic Square program The Lo Shu Magic Square is a grid with 3 rows

In java, create a java class to complete the Lo Shu Magic Square program

The Lo Shu Magic Square is a grid with 3 rows and 3 columns. The Lo Shu Magic Square has the following properties:

- The grid contains the numbers 1 through 9 exactly. (10 pts)

- The sum of each row, each column, and each diagonal all add up to the same number (shown below). (20 pts)

You will create a new class called LoShuMagic.java. This class will contain one method called test. This method will take a 3x3 int array as a parameter and will return a Boolean. The return value will be true if the 3x3 array fulfills the two properties of a Lo Shu Magic Square, and will be false otherwise. I have provided you with LoShuClassTester.java. You will not change this file at all. You must create the LoShuMagic.java class to make it work. The code for LoShuClassTester.java is below.

public class LoShuClassTester { public static void main(String[] args) { LoShuMagic lsm = new LoShuMagic(); int matrix[][] = new int[3][3]; matrix[0][0] = 4; matrix[0][1] = 9; matrix[0][2] = 2; matrix[1][0] = 3; matrix[1][1] = 5; matrix[1][2] = 7; matrix[2][0] = 8; matrix[2][1] = 1; matrix[2][2] = 6; if(lsm.test(matrix)==true) { System.out.println("Test 1 passed"); }else { System.out.println("Test 1 failed"); } matrix[0][1] = 10; if(lsm.test(matrix)==false) { System.out.println("Test 2 passed"); }else { System.out.println("Test 2 failed"); } } } 

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!