Question
// **************************************** // MagicSquare.java //// Text below is to be filled by student. //// **************************************************************** import java.util.Scanner; public class MagicSquare {int[][] square; public MagicSquare(int size){}
// **************************************** // MagicSquare.java //// Text below is to be filled by student. //// **************************************************************** import java.util.Scanner; public class MagicSquare {int[][] square;
public MagicSquare(int size){} //-------------------------------------- //return the sum of the values in the given row //-------------------------------------- private int sumMagicRow(int row){int sum = 0; return sum;} //-------------------------------------- //return the sum of the values in the given column //-------------------------------------- private int sumMagicCol(int col) { int sum = 0; // return sum;} //-------------------------------------- //return the sum of the values in the main diagonal //-------------------------------------- private int sumMagicDiagMain() {int sum = 0; // return sum;} //-------------------------------------- //return the sum of the values in the other ("reverse") diagonal //-------------------------------------- private int sumMagicDiagRev(){int sum = 0;// ......return sum; }//-------------------------------------- //return true if the square is magic (all rows, cols, and diags// have same sum), false otherwise //-------------------------------------- public boolean isMagicSquare(){boolean answer = true; // return answer;} //-------------------------------------- //compute and display sums of square including row, column, main diagonal, and other diagonal //-------------------------------------- public void printMagicSquareSums() {// } //-------------------------------------- //read info into the square from the input stream associated with//the Scanner parameter //-------------------------------------- public void readSquare(Scanner scan) { for (int row = 0; row < square.length; row++) for (int col = 0; col < square.length; col++) square[row][col] = scan.nextInt();} //-------------------------------------- //print the contents of the square, neatly formatted //-------------------------------------- public void printSquare(){ } }
-------------------------------------------------------------------------------------------------------------------------------------
// **************************************************************** // MagicSquareTest.java //// Text below is to be filled by student. //// **************************************************************** import java.util.Scanner; import java.io.IOException; import java.io.File; public class MagicSquareTest { public static void main(String[] args) throws IOException { Scanner scan = new Scanner(new File("magicText.txt")); // make sure that the file magicData is in the current directoryint count = 1; //count which square we're onint size = scan.nextInt(); //size of next square //Expecting -1 at bottom of input filewhile (size != -1) { //create a new Square of the given sizeMagicSquare s = new MagicSquare(size); //call its read method to read the values of the square System.out.println(" ***** Square " + count + " *****");s.readSquare(scan); //print the squares.printSquare(); //print the square id//print the sums //determine and print whether it is a magic square //get size of next square size = scan.nextInt(); count++; } } }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started