0

I am writing a tic tac toe game in java. Right now I am currently stuck on the display board method. The board I am trying to create has lines in which the X's and O's will go into. The error I am currently getting is

TicTac2.java:56: error: illegal start of type return result; ^ TicTac2.java:56: error: ';' expected return result;

I will update this code as I go along it with little problems I encounter. I love this site because it helps so much! Anyway here is my code:

    import java.util.*;

public class TicTac2{
   //declare a constant variable
   public enum Cell {E, X, O};  //this is an O, not 0

   public Cell[][] board;

   public static final int SIZE = 3; //size of each row and each column

   public static void main(String[] args) {
       displayBoard a = new displayBoard();
       System.out.println(a);
   }      

   //displayBoard method
   public static void drawLine() {
      for (int i = 0; i <= 4 * SIZE; i++) {
         System.out.print("-");
      }
      System.out.println();
   }
   public static void displayBoard(char[][] board) {
      drawLine();
      for (int i = 0; i < SIZE; i++) {
         for (int j = 0; j < SIZE; j++) {
            SIZE[i][j] = Cell.E;
            System.out.print("| " + board[i][j] + " ");
         }
         System.out.println("|");
         drawLine();
      }
      System.out.println();
   }
   public String toString(){
      String result = "";
      for(Cell[] row : board) {
         for(Cell col : row)
            result += col;
         }
         result =+ "\n";
      }   
      return result;


   }
jSeesFor3ver
  • 83
  • 4
  • 16
  • SIZE[i][j] = Cell.E; is this correct? – kosa Oct 22 '13 at 18:51
  • 1
    The idea is that you ask a question when stuck, and pick the answer. This way others can benefit from the question and answer too. – flup Oct 22 '13 at 18:53
  • I was stuck? I guess I didn't define a real clear question in my post, but reading it you can see that I'm asking about my return result line and why it doesn't work. – jSeesFor3ver Oct 22 '13 at 21:00

2 Answers2

1

You are missing a { bracket

for(Cell col : row) { // <--- add this guy
     result += col;
}

Consider learning to use an IDE. An IDE will point out these errors almost immediately. It will also find all other syntax errors.

Sotirios Delimanolis
  • 274,122
  • 60
  • 696
  • 724
  • I am using jGrasp which is what my professor recommended, however I've seen tutorials use eclipse which seems to work a lot better as you write your code. Would you recommend eclipse over jGrasp? Also I can't believe I didn't see the bracket, holy eff that was dumb. – jSeesFor3ver Oct 22 '13 at 20:58
  • @user2861029 I don't know `jGrasp`, but almost definitely, yes! – Sotirios Delimanolis Oct 22 '13 at 20:59
1

displayBoard a = new displayBoard();
System.out.println(a);

I'm confused by these lines.

You are defining DisplayBoard as a method that takes in a two-dimensional array of Cells, but in the code above you are treating it like a class.

You don't want to create a displayBoard object (as it isn't a class), you just want to call the methods (and pass in board!).

hankd
  • 649
  • 3
  • 12
  • How would I call my method to display my board? My display line method works. I am still having trouble getting my board to be displayed. – jSeesFor3ver Oct 22 '13 at 21:55