Project 5 - Magic Squares Objectives The objective of this project is to have students practice with two-dimensional arrays and loops. Specifications n this project, you will write code to determine if a two-dimensional array of ints is a Magic Square. For a two- dimensional array of ints to be a Magic Square all of the following must be true: 1. The array must be square - in other words, the lengths of all rows and all columns must be the same. 2. The array must contain all integers from 1 to n*n, where n is the length of the rows and columns. 3. The sum of the numbers in each diagonal, each row, and each column must be the same. You have been given two classes: • MagicSquareTest.java - contains JUnit test cases for the MagicSquare class. Your code must pass all these tests. • MagicSquare.java - contains static methods to determine if a two-dimensional array of ints is a Magic Square: o isMagicSquare() - returns true if a two-dimensional array of ints meets all the criteria to be a Magic Square. This method is already completed for you. It uses all of the following methods: . issquare() - returns true if a two-dimensional array of ints is a square - in other words, the lengths of all rows and columns are the same. This method is already completed for you. • containsAllNumbers() - returns true if a square two-dimensional array of ints contains all integers from 1 to n*n, where n is the length of the rows and columns. This method is already completed for you. • diagonal1Sum() - returns the sum of the numbers in the upper-left to lower-right diagonal of a square two- dimensional array of ints . You must write the body for this method. • diagonal2Sum() - returns the sum of the numbers in the upper-right to lower-left diagonal of a square two- dimensional array of ints . You must write the body for this method. • rowSums () - if all the rows of a square two-dimensional array of ints have the same sum, returns that sum. Otherwise, returns -1. You must write the body for this method. It uses the following: . rowSum() - returns the sum of the numbers in a given row. You must write the body for this method. • colSums () - if all the columns of a square two-dimensional array of ints have the same sum, returns tha sum. Otherwise, returns -1. You must write the body for this method. Uses: • colSum() - returns the sum of the numbers in a given column. You must write the body for this method.

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question
100%
Project 5 - Magic Squares
Objectives
The objective of this project is to have students practice with two-dimensional arrays and loops.
Specifications
In this project, you will write code to determine if a two-dimensional array of ints is a Magic Square. For a two-
dimensional array of ints to be a Magic Square all of the following must be true:
1. The array must be square - in other words, the lengths of all rows and all columns must be the same.
2. The array must contain all integers from 1 to n*n, where n is the length of the rows and columns.
3. The sum of the numbers in each diagonal, each row, and each column must be the same.
You have been given two classes:
• MagicSquareTest.java - Contains JUnit test cases for the MagicSquare class. Your code must pass all these tests.
• MagicSquare.java - contains static methods to determine if a two-dimensional array of ints is a Magic Square:
o isMagicSquare() - returns true if a two-dimensional array of ints meets all the criteria to be a Magic Square.
This method is already completed for you. It uses all of the following methods:
· issquare() - returns true if a two-dimensional array of ints is a square - in other words, the lengths of
all rows and columns are the same. This method is already completed for you.
• containsAllNumbers() - returns true if a square two-dimensional array of ints contains all integers from
1 to n*n, where n is the length of the rows and columns. This method is already completed for you.
• diagonal1Sum() - returns the sum of the numbers in the upper-left to lower-right diagonal of a square two-
dimensional array of ints . You must write the body for this method.
1 diagonal2Sum() - returns the sum of the numbers in the upper-right to lower-left diagonal of a square two-
dimensional array of ints . You must write the body for this method.
I rowSums () - if all the rows of a square two-dimensional array of ints have the same sum, returns that
sum. Otherwise, returns -1. You must write the body for this method. It uses the following:
• rowSum() - returns the sum of the numbers in a given row. You must write the body for this
method.
. colSums () - if all the columns of a square two-dimensional array of ints have the same sum, returns that
sum. Otherwise, returns -1. You must write the body for this method. Uses:
- colSum() - returns the sum of the numbers in a given column. You must write the body for this
method.
Transcribed Image Text:Project 5 - Magic Squares Objectives The objective of this project is to have students practice with two-dimensional arrays and loops. Specifications In this project, you will write code to determine if a two-dimensional array of ints is a Magic Square. For a two- dimensional array of ints to be a Magic Square all of the following must be true: 1. The array must be square - in other words, the lengths of all rows and all columns must be the same. 2. The array must contain all integers from 1 to n*n, where n is the length of the rows and columns. 3. The sum of the numbers in each diagonal, each row, and each column must be the same. You have been given two classes: • MagicSquareTest.java - Contains JUnit test cases for the MagicSquare class. Your code must pass all these tests. • MagicSquare.java - contains static methods to determine if a two-dimensional array of ints is a Magic Square: o isMagicSquare() - returns true if a two-dimensional array of ints meets all the criteria to be a Magic Square. This method is already completed for you. It uses all of the following methods: · issquare() - returns true if a two-dimensional array of ints is a square - in other words, the lengths of all rows and columns are the same. This method is already completed for you. • containsAllNumbers() - returns true if a square two-dimensional array of ints contains all integers from 1 to n*n, where n is the length of the rows and columns. This method is already completed for you. • diagonal1Sum() - returns the sum of the numbers in the upper-left to lower-right diagonal of a square two- dimensional array of ints . You must write the body for this method. 1 diagonal2Sum() - returns the sum of the numbers in the upper-right to lower-left diagonal of a square two- dimensional array of ints . You must write the body for this method. I rowSums () - if all the rows of a square two-dimensional array of ints have the same sum, returns that sum. Otherwise, returns -1. You must write the body for this method. It uses the following: • rowSum() - returns the sum of the numbers in a given row. You must write the body for this method. . colSums () - if all the columns of a square two-dimensional array of ints have the same sum, returns that sum. Otherwise, returns -1. You must write the body for this method. Uses: - colSum() - returns the sum of the numbers in a given column. You must write the body for this method.
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps

Blurred answer
Knowledge Booster
Array
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education