subject
Computers and Technology, 25.02.2020 20:25 jeanieb

A magic square is a square matrix (N rows by N columns) with the following properties: 1. It 1 contains the numbers 1 through N2, with each number appearing exactly once. 2. The sums of each row, each column, and both main diagonals are equal. For example, here is a "3 by 3" magic square: 4 9 2 3 5 7 8 1 6 The assignment is to create a class to model a magic square and a test class for it.

I. The MagicSquare ClassYour magic square class constructor will have a parameter for N (the number of rows and columns) and will call a private "utility" method that fills the square with the integers 1 to N. Your class will contain 2 additional methods:A method that returns a value of true or false indicating whether the square created is indeed magic. That is, whether all the sums – those of each individual row and column and of both diagonals – are equal. (Hint: for an N by N matrix, how many sums must be tested?)A toString method that returns the magic square as a multi-line string, as shown above. II. The Test ClassYour test class will get the number of rows and columns from the user, create a magic square object, and call the method that tests whether the square is truly magical. If so, it will call the toString method and print the square; otherwise, an error message should be printed. Use a loop to ensure that your program accepts only positive, odd-numbered values for NIII. AlgorithmFortunately, there is a straightforward algorithm to create an "N by N" magic square, where N is an odd number: 1. Place a 1 in the middle column of the last row. 2. Place the integers from 2 to N2 into the matrix in succession, according to these rules:Attempt to place each number in a position that is one row below and one column to the right of the previous number. If the attempt leads to a non-existent row, then the number is placed instead in the first row, one column to the right. If the attempt leads to a non-existent column, then the number is placed instead in the first column, one row down. If the attempt leads to a non-existent row and a non-existent column, then the number is placed instead in the position directly above the previous number (i. e., same column, previous row).If the attempt leads to a position that is not empty (i. e., already contains a value), then the number is placed instead in the position directly above the previous number. No credit will be given for programs that use any algorithm to generate the square other than the one described above

ansver
Answers: 3

Another question on Computers and Technology

question
Computers and Technology, 22.06.2019 13:00
Why the bear has a slunky tail determine the meaning of the word slunk in the story
Answers: 1
question
Computers and Technology, 24.06.2019 04:30
The ieee 802.11: defines standards for wireless local area network (wlan) communication protocols. identifies various computers or devices connected to a network. verifies any resource attached to another computer on a network that is different from the computer to which the user is logged on. connects multiple local area networks (lans) and wide area networks (wans).
Answers: 2
question
Computers and Technology, 24.06.2019 12:40
Match the feature to the network architecture. expensive to set up useful for a small organization easy to track files has a central server inexpensive to set up difficult to track files useful for a large organization does not have a central server client- server network peer-to-peer network
Answers: 3
question
Computers and Technology, 25.06.2019 08:20
The control unit takes ths instructions fetched by the preteched unit and translates them into a form that can be understood by
Answers: 1
You know the right answer?
A magic square is a square matrix (N rows by N columns) with the following properties: 1. It 1 conta...
Questions
question
Mathematics, 16.12.2020 03:20
question
Mathematics, 16.12.2020 03:20
question
Mathematics, 16.12.2020 03:20
question
French, 16.12.2020 03:20
question
Mathematics, 16.12.2020 03:20
Questions on the website: 13722363