// **************************************************************** // SquareTest.java // // Uses the Square class to read in square data and tell if // each square is magic. // // **************************************************************** import java.io.*; public class SquareTest { public static void main(String[] args) throws IOException { int count = 1; //count which square we're on BufferedReader keyboard = new BufferedReader(new InputStreamReader(System.in)); System.out.print("\nEnter the name of the input file: "); String fileName = keyboard.readLine(); FileReader fr = new FileReader(fileName); BufferedReader infile = new BufferedReader(fr); // read the size of the square from the input file int size = Integer.parseInt(infile.readLine()); // expecting -1 at bottom of input file while (size != -1) { Square square = new Square(size,infile); //create a new Square of the given size //call its read method to read the values of the square square.readSquare(); System.out.println("\n******** Square " + count++ + " ********"); //** print the square //** print the sums of its rows //** print the sums of its columns //** print the sum of the main diagonal //** print the sum of the other diagonal //** determine and print whether it is a magic square // read the size of the square from the input file size = Integer.parseInt(infile.readLine()); } } }