Here is my Squares code:
import java.util.ArrayList;
import java.util.Scanner;
/**
This class tests whether a sequence of inputs forms a magic square.
Xxxx is replaced by student's last name
*/
public class Squares
{
int[][] table;
int[][] square;
int column, sumC;
int row, sumR;
int size;
int sumDiag, sumReverse;
//create new square of g
public Squares(int size)
{
int square[][] = new int [size][size]; // table user defined
}
//return the sum of the values in the given row
public int sumRow(int row)
{
int sumRow = 0;
for(column = 0; column < square.length; column++)
{
sumR = sumR + table[row][column];
}
return sumR;
}
//return the sum of the values in the given column
public int sumCol(int col)
{
int sumC = 0;
for(row = 0; row < size; row++)
{
sumC = sumC + table[row][column];
}
return sumC;
}
//return the sum of the values in the main diagonal
public int sumMainDiag()
{
int sumDiag = 0;for (row = 0, column = square.length - 1; row < square.length; row++)
{
sumDiag += square[row][column];
column --;
}
return sumDiag;
}
//return the sum of the values in the other ("reverse") diagonal
public int sumOtherDiag()
{
int sumReverse = 0;
for (row = square.length-1, column = 0; column < square.length; row--)
{
sumReverse += square[row][column];
column++;
}
return sumReverse;
}
//return true if the square is magic (all rows, cols, and diags have same sum), false otherwise
public boolean isMagic()
{
boolean result = false;
if (sumR == sumC)
if (sumC == sumDiag)
if (sumDiag == sumReverse)
result = true;
return result;
}
//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][column] = scan.nextInt();
}
//print the contents of the square, neatly formatted
public void printSquare()
{
for (int row = 0; row < table[row].length; row++)
{
for (int col = 0; col < table[row].length; col++)
System.out.println();
}
}
}
This is the "main" code:
import java.util.ArrayList;
import java.util.Scanner;
/**
This class tests whether a sequence of inputs forms a magic square.
Xxxx is replaced by student's last name
*/
public class Squares
{
int[][] table;
int[][] square;
int column, sumC;
int row, sumR;
int size;
int sumDiag, sumReverse;
//create new square of g
public Squares(int size)
{
int square[][] = new int [size][size]; // table user defined
}
//return the sum of the values in the given row
public int sumRow(int row)
{
int sumRow = 0;
for(column = 0; column < square.length; column++)
{
sumR = sumR + table[row][column];
}
return sumR;
}
//return the sum of the values in the given column
public int sumCol(int col)
{
int sumC = 0;
for(row = 0; row < size; row++)
{
sumC = sumC + table[row][column];
}
return sumC;
}
//return the sum of the values in the main diagonal
public int sumMainDiag()
{
int sumDiag = 0;for (row = 0, column = square.length - 1; row < square.length; row++)
{
sumDiag += square[row][column];
column --;
}
return sumDiag;
}
//return the sum of the values in the other ("reverse") diagonal
public int sumOtherDiag()
{
int sumReverse = 0;
for (row = square.length-1, column = 0; column < square.length; row--)
{
sumReverse += square[row][column];
column++;
}
return sumReverse;
}
//return true if the square is magic (all rows, cols, and diags have same sum), false otherwise
public boolean isMagic()
{
boolean result = false;
if (sumR == sumC)
if (sumC == sumDiag)
if (sumDiag == sumReverse)
result = true;
return result;
}
//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][column] = scan.nextInt();
}
//print the contents of the square, neatly formatted
public void printSquare()
{
for (int row = 0; row < table[row].length; row++)
{
for (int col = 0; col < table[row].length; col++)
System.out.println();
}
}
}
This is the error message I am getting back:
symbol : constructor Squares(java.util.ArrayList<java.lang.Integer>)
location: class Squares
Squares mySquare = new Squares(numbers);
^
SquaresReader.java:44: cannot find symbol
symbol : variable count
location: class SquaresReader
System.out.println("\n******** Square " + count + " ********");
^
2 errors
----jGRASP wedge: exit code for process is 1.
----jGRASP: operation complete.
Can anyone help with this. I am trying to get the ArrayList to be built by the user input, then read by the program, and determined to be or not be a magic square or not a square at all. Also, I want to restrict the program to not crashing if something other than an Integer or "Q" is input by the user. i want it to have an exit statement but I'm not sure how I would construct that or where to include.
Thanks for any help that can be provided!

New Topic/Question
Reply




MultiQuote








|