// **************************************************************** // // Square.java // // Define a Square class with methods to create and read in // info for a square matrix and to compute the sum of a row, // a col, either diagonal, and whether it is magic. // // **************************************************************** import java.util.StringTokenizer; import java.io.*; public class Square { BufferedReader infile; int[][] square; //---------------------------------------------------------------------------- //create new square as a two-dimensional array with size rows and size columns //---------------------------------------------------------------------------- public Square(int size, BufferedReader fileReader ) { square = new int[size][size]; infile = fileReader; } //--------------------------------------------- //return the sum of the values in the given row //--------------------------------------------- public int sumRow(int row) { // place your code here } //------------------------------------------------ //return the sum of the values in the given column //------------------------------------------------ public int sumCol(int col) { // place your code here } //------------------------------------------------- //return the sum of the values in the main diagonal //------------------------------------------------- public int sumMainDiag() { // place your code here } //-------------------------------------------------------------- //return the sum of the values in the other ("reverse") diagonal //-------------------------------------------------------------- public int sumOtherDiag() { // place your code here } //------------------------------------------------------------------ //return true if the square is magic (all rows, cols, and diags have //same sum), false otherwise //------------------------------------------------------------------ public boolean magic() { // place your code here } //-------------------------------------------------- //read info into the square from the standard input. //-------------------------------------------------- public void readSquare() throws IOException { StringTokenizer tokenizer; String line; for (int row = 0; row < square.length; row++) { line = infile.readLine(); tokenizer = new StringTokenizer(line); for (int col = 0; col < square.length; col ++) square[row][col] = Integer.parseInt(tokenizer.nextToken()); } } //-------------------------------------------------- //print the contents of the square, neatly formatted //-------------------------------------------------- public void printSquare() { // place your code here } }