Im trying to create a printable on command promt board in order to manage to create a TicTacToe game in CMD. Although,when i create the class for my board and my cells, Java throws an error under my print and println saying me that:
symbol: method println() -or- method print() .etc...
location: class board
error: cannot find symbol
whats the problem with my code? Here is my whole .java file:
i just want it to compile,not to run
import acm.program.*;
public class board {
private static final int ROWS=3;
private static final int COLS=3;
private int[][] board1 = new int[ROWS][COLS];
//constructor
public board() {
for (int i = 0; i < 3; i++) {
for (int j = 0; j < 3; j++) {
board1[i][j]=0;
printBoard();
}
}
}
public void printBoard() {
for(int row =0; row<ROWS; row++) {
for (int col=0; col<COLS; col++) {
printCell(board1[row][col]);
if (col != (COLS-1)) {
print("|"); // print vertical partition
}
}
println();
if (row !=(ROWS-1)) {
println("-----------");
}
}
println();
}
public void printCell(int content) {
if (content == 0) {print(" ");}
}
}
It compiles just by replacing print() and println() with system.out. But this is too weird. ACM package includes methods like println() and print() in order to make it easier. but now it is fixed. Thank you.
EDIT 2: in order to compile with print() and println() IT IS A NEED to have: "public class board extends Program" and NOT just "public class board"
Here is the corrected code:
public class board {
private static final int ROWS=3;
private static final int COLS=3;
private int[][] board1 = new int[ROWS][COLS];
//constructor
public board() {
for (int i = 0; i < 3; i++) {
for (int j = 0; j < 3; j++) {
board1[i][j]=0;
printBoard();
}
}
}
public void printBoard(){
for(int row =0; row<ROWS; row++){
for (int col=0; col<COLS; col++){
printCell(board1[row][col]);
if (col != (COLS-1)) {
System.out.print("|"); // print vertical partition
}
}
System.out.println("");
if (row !=(ROWS-1)) {
System.out.println("-----------");
}
}
System.out.println();
}
public void printCell(int content) {
if (content == 0) {System.out.print(" ");}
}
}
You were just missing some calls to "System.out" for the print statements.