1

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"

HpdsbuΖt
  • 103
  • 2
  • 2
  • 9
  • 2
    If you want to use ACM, you must have `acm.jar` file in your classpath and your class `board` you must `extend Program` class like: `class board extends Program{}` – Rong Nguyen Feb 07 '14 at 03:48
  • i have the acm.jar file in my classpath. But do i need to extend the Program like "extends Program" when i create a simple class,with a constructor? Constructor "public board" is being "loaded" into a new .java file,which has also the acm imported and "extends Program" .. – HpdsbuΖt Feb 07 '14 at 03:51
  • 1
    It's not true in `Java`, so you need to sure `Constructor "public board" is being "loaded" into a new .java `. – Rong Nguyen Feb 07 '14 at 03:56

3 Answers3

3

Try to replace println() and print() by

System.out.print();
System.out.println();

If you want to use ACM, you must have acm.jar file in your classpath and you must extend Program class in your board class like: class board extends Program{}

See also:

Community
  • 1
  • 1
Rong Nguyen
  • 4,143
  • 5
  • 27
  • 53
1

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.

Alvin Bunk
  • 7,621
  • 3
  • 29
  • 45
  • yes.it compiles! but it is too weird. ACM package includes methods like println() and print() in order to make it easier. but now.. – HpdsbuΖt Feb 07 '14 at 03:35
  • Hi there @HpdsbuΖt. Do you need your "acm.program.*" imports? I didn't use any, and my program compiled. If it is needed, can you tell us some information about the package? – Alvin Bunk Feb 07 '14 at 03:38
  • yes. ACM package provides you some commands and tools to make it "easier" to write code with Java and especially to create Graphic programs such as games. It provides you with more simple commands from the "ordinary java" like: pintln() ---> system.out.println() public void run() --> public static void main(String[] args) we use it in the first year and the first semester @ my university (cs) – HpdsbuΖt Feb 07 '14 at 03:41
  • So @HpdsbuΖt, did my solution help except for you don't need to use "System.out" instead of just "print" and "println" with the ACM JTF package? If so, can you upvote my answer? – Alvin Bunk Feb 07 '14 at 03:45
0

Change println() by

System.out.print(); or   
System.out.println();

For More

Rakesh KR
  • 6,357
  • 5
  • 40
  • 55