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, 23.06.2019 06:00
Which statement is true of web-based social media? a.they allow consumers to interact with and update content. b.they cannot be updated easily, as compared to print media. c.they are expensive to produce and maintain, as compared to print and television. d.they can exist independent of the internet.
Answers: 1
question
Computers and Technology, 23.06.2019 10:00
Hey i just logged on and one of the moderators deleted a bunch of my answers to questions, even though the answers were right and the people it doesn't make sense but if anyone wants to talk about anything just message me lol (this is super random lol)
Answers: 1
question
Computers and Technology, 23.06.2019 19:30
Amitha writes up a one-page summary of a novel during her summer internship at a publishing company. when she reads over the page, she realizes she used the word β€œforeshadow” seven times, and she would like to reduce the repetition. which tool would best amitha solve this problem?
Answers: 3
question
Computers and Technology, 23.06.2019 23:40
Which of the following calculates the total from the adjacent cell through the first nonnumeric cell by default, using the sum function in its formula? -average -autosum -counta -max
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
Chemistry, 11.11.2020 01:50
question
History, 11.11.2020 01:50
Questions on the website: 13722362