Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

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

Recommended Textbook for

Data Management Databases And Organizations

Authors: Watson Watson

5th Edition

0471715360, 978-0471715368

More Books

Students also viewed these Databases questions

Question

What does Processing of an OLAP Cube accomplish?

Answered: 1 week ago