Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I need to create a 'magic square' java program. A magic square is an NxN matrix of numbers such that the values in each row,

I need to create a 'magic square' java program.

A magic square is an NxN matrix of numbers such that the values in each row, column and diagonal add up to the same number. Write a class called MagicSquare that determines whether a given square is a magic square.

MagicSquare will have the following static methods. The class will have two public methods:

displaySquare will accept a 2D array of integers and display the contents of the 2D square/array as shown above

. checkSquare will accept a 2D array of integers and return true if the 2D square is magic and false if it is not.

You will also write four private helper methods:

checkRow will take an integer identifying a row and will return the sum of the values in that row

checkColumn will take an integer identifying a column and will return the sum of the values in that column

checkDiag1 will return the sum of the values in the diagonal from the top-left to the bottom righ

t checkDiag2 will return the sum of the values in the diagonal from the bottom-left to the top-right

The txt file is:

Magic Square data 2 7 6 9 5 1 4 3 8 4 14 15 1 9 7 6 12 5 11 10 8 16 2 3 13 Non-Magic Square 2 3 4 8 1 7 10 5 2 13 14 15 1 9 7 6 12 5 11 10 8 16 2 3 4 

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

Machine Learning And Knowledge Discovery In Databases European Conference Ecml Pkdd 2010 Barcelona Spain September 2010 Proceedings Part 3 Lnai 6323

Authors: Jose L. Balcazar ,Francesco Bonchi ,Aristides Gionis ,Michele Sebag

2010th Edition

3642159389, 978-3642159381

More Books

Students also viewed these Databases questions

Question

Estimate the moment of inertia of a bicycle wheel.

Answered: 1 week ago

Question

What are the stages of project management? Write it in items.

Answered: 1 week ago

Question

why do consumers often fail to seek out higher yields on deposits ?

Answered: 1 week ago