Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 5 of 5

Thread: Why am I getting 62 errors?

  1. #1
    Junior Member
    Join Date
    Dec 2008
    Posts
    11
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Why am I getting 62 errors?

    Here is my code that I have completed:

    import java.util.Scanner;
    import java.util.Random;
     
     
    public class user_Life
    {
     
    	// the size of the grid (GRIDSIZE x GRIDSIZE)
    	final private static int GRIDSIZE = 18;
     
    	//************************************************************************************************
    	public static void main ( String args[] )
    	{ 	
    		boolean[][] board = new boolean[GRIDSIZE][GRIDSIZE];
    		char choice;
    		int x = 1;
    		Scanner sc = new Scanner ( System.in );
     
    		do
    		{
    			System.out.print ( "Start with a (r)andom board, the (q)ueen bee shuttle or the (g)lider pattern? ");
    			choice = sc.next().charAt(0);
    		} while ( choice != 'r' && choice != 'q' && choice != 'g' );
     
    		clearGrid (board);
    		setup(board, choice);
     
    		do
    		{
    			System.out.printf ("Viewing generation #%d:\n\n", x++);
    			displayGrid(board);
    			genNextGrid(board);
    			System.out.print ("\n(q)uit or any other key + ENTER to continue: ");
    			choice = sc.next().charAt(0);
    		} while ( choice != 'q' );
    	}
     
    	//***********************************************************************************************
    	public static void setup (boolean[][] board, char which)
    	{
    		Random randomNumbers = new Random ();
     
    		clearGrid(board);
     
    		if ( which == 'q' )
    		{
    			//Set up the Queen Bee Pattern
    			board[5][1] = true;board[5][2] = true;board[6][3] = true;board[7][4] = true;
    			board[8][4] = true;board[9][4] = true;board[10][3] = true;board[11][2] = true;
    			board[11][1] = true;
    		}
    		else if ( which == 'g' )
    		{
    			//Set up the Glider
    			board[17][0] = true;board[16][1] = true;board[15][1] = true;
    			board[16][2] = true;
    			board[17][2] = true;
    		}
    		else
    			//Set up Random
    			for (int row = 0; row < board.length; row++ )
    			{
    				for (int col = 0; col < board[row].length; col++ )
    				{
    					if ( randomNumbers.nextInt() % 2 == 0 )
    					     board[row][col] = true;
    				}
    			}
    		}
    	}
    	//*******************************************************************************************************
    	public static void displayGrid (boolean[][] grid)
    	{
    		//Start printing the top row of numbers
    		System.out.print ("   ");
    		for (int x = 1; x <= grid.length; x++)
    		{
    			if ((x/10) != 0)
    				System.out.printf ( "%d", x / 10 );
    			else
    				System.out.print ( "  " );
    		}
     
    		System.out.println();
    		System.out.print( "   " );
     
    		for (int x = 1; x <= grid.length; x++)
    		{
    			System.out.print ( "%d", x % 10 );
    		}
    		System.out.println();
     
    		for (int r = 0; r < grid.length; r++)
    		{
    			System.out.printf ( "%d", r+1 );
    			if ( r + 1 < 10)
    				System.out.print ( "  " );
    			else 
    				System.out.print ( " " );
    			for (int c = 0; c < grid.length; c++)
    			{
    				if (grid[r][c] ==  true)
    					System.out.print ( "*" );
    				else 
    					System.out.print ( " " ); 
    			}
    			System.out.println();
    		}
    	}
     
    //*****************************************************************************************************************
     
    // Put the three methods you must write here and make sure to document
    // them!
     
    public static void clearGrid ( boolean[][] board )
    {
    	for (int row=0; row<board.length; row++)
    	{
    		for (int col=0; col<board[row].length; col++)
    		{ 
    			board[row][col] = false;
    		}
    	}
    }
     
    public static void genNextGrid ( boolean[][] board )
    {
    boolean[][] temp=new boolean[GRIDSIZE][GRIDSIZE];
    for (int row=0; row<18; row++)
    {
    	for (int col=0; col<18; col++)
    	{
    		int count=countNeighbors(board,row,col);
    		switch(count)
    		{
    			case 0: case 1:
    				temp[row][col] = false;
    				break;
    			case 2:
    			if(temp[row][col])
    			{
    				temp[row][col] = true;
    			}
    			if (!temp[row][col])
    			{
    				temp[row][col] = false;
    			}
    			break;
    			case 3: 
    				temp[row][col] = true;
    				break;
    			case 4: case 5: case 6: case 7: case 8:
    				temp[row][col] = false;
    				break;
    			}
    		}
    	}
    		for (int row=0; row<18; row++)
    		{
    			for (int col=0; col<18; col++)
    			{
    		board [row][col]=temp[row][col];
    			}
    		}
    	}
     
    public static int countNeighbors ( final boolean[][] board, final int row, final int col )
    {
    int ncount=0;
    for (int r=row-1; r<= row+1; r++)
    {
    	if(row<0||row>=GRIDSIZE)
    	{
    		continue;
    	}		
    	for (int c=col-1; c<=col+1; c++)
    	{
    		if(col<=||col>=GRIDSIZE||(r==row && c==col))
    		{
    			continue;
    		}
    		if (board[row][col])
    		{
    			ncount++;
    		}
    	}
    }
    return ncount;
     
    }
    }

    And sadly these are my errors:

    user_Life.java:88: class, interface, or enum expected
            public static void displayGrid (boolean[][] grid)
                          ^
    user_Life.java:92: class, interface, or enum expected
                    for (int x = 1; x <= grid.length; x++)
                    ^
    user_Life.java:92: class, interface, or enum expected
                    for (int x = 1; x <= grid.length; x++)
                                    ^
    user_Life.java:92: class, interface, or enum expected
                    for (int x = 1; x <= grid.length; x++)
                                                      ^
    user_Life.java:96: class, interface, or enum expected
                            else
                            ^
    user_Life.java:98: class, interface, or enum expected
                    }
                    ^
    user_Life.java:101: class, interface, or enum expected
                    System.out.print( "   " );
                    ^
    user_Life.java:103: class, interface, or enum expected
                    for (int x = 1; x <= grid.length; x++)
                    ^
    user_Life.java:103: class, interface, or enum expected
                    for (int x = 1; x <= grid.length; x++)
                                    ^
    user_Life.java:103: class, interface, or enum expected
                    for (int x = 1; x <= grid.length; x++)
                                                      ^
    user_Life.java:106: class, interface, or enum expected
                    }
                    ^
    user_Life.java:109: class, interface, or enum expected
                    for (int r = 0; r < grid.length; r++)
                    ^
    user_Life.java:109: class, interface, or enum expected
                    for (int r = 0; r < grid.length; r++)
                                    ^
    user_Life.java:109: class, interface, or enum expected
                    for (int r = 0; r < grid.length; r++)
                                                     ^
    user_Life.java:112: class, interface, or enum expected
                            if ( r + 1 < 10)
                            ^
    user_Life.java:114: class, interface, or enum expected
                            else
                            ^
    user_Life.java:116: class, interface, or enum expected
                            for (int c = 0; c < grid.length; c++)
                            ^
    user_Life.java:116: class, interface, or enum expected
                            for (int c = 0; c < grid.length; c++)
                                            ^
    user_Life.java:116: class, interface, or enum expected
                            for (int c = 0; c < grid.length; c++)
                                                             ^
    user_Life.java:120: class, interface, or enum expected
                                    else
                                    ^
    user_Life.java:122: class, interface, or enum expected
                            }
                            ^
    user_Life.java:124: class, interface, or enum expected
                    }
                    ^
    user_Life.java:132: class, interface, or enum expected
    public static void clearGrid ( boolean[][] board )
                  ^
    user_Life.java:134: class, interface, or enum expected
            for (int row=0; row<board.length; row++)
                            ^
    user_Life.java:134: class, interface, or enum expected
            for (int row=0; row<board.length; row++)
                                              ^
    user_Life.java:136: class, interface, or enum expected
                    for (int col=0; col<board[row].length; col++)
                                    ^
    user_Life.java:136: class, interface, or enum expected
                    for (int col=0; col<board[row].length; col++)
                                                           ^
    user_Life.java:139: class, interface, or enum expected
                    }
                    ^
    user_Life.java:143: class, interface, or enum expected
    public static void genNextGrid ( boolean[][] board )
                  ^
    user_Life.java:146: class, interface, or enum expected
    for (int row=0; row<18; row++)
    ^
    user_Life.java:146: class, interface, or enum expected
    for (int row=0; row<18; row++)
                    ^
    user_Life.java:146: class, interface, or enum expected
    for (int row=0; row<18; row++)
                            ^
    user_Life.java:148: class, interface, or enum expected
            for (int col=0; col<18; col++)
                            ^
    user_Life.java:148: class, interface, or enum expected
            for (int col=0; col<18; col++)
                                    ^
    user_Life.java:151: class, interface, or enum expected
                    switch(count)
                    ^
    user_Life.java:155: class, interface, or enum expected
                                    break;
                                    ^
    user_Life.java:156: class, interface, or enum expected
                            case 2:
                            ^
    user_Life.java:160: class, interface, or enum expected
                            }
                            ^
    user_Life.java:164: class, interface, or enum expected
                            }
                            ^
    user_Life.java:166: class, interface, or enum expected
                            case 3:
                            ^
    user_Life.java:168: class, interface, or enum expected
                                    break;
                                    ^
    user_Life.java:169: class, interface, or enum expected
                            case 4: case 5: case 6: case 7: case 8:
                            ^
    user_Life.java:171: class, interface, or enum expected
                                    break;
                                    ^
    user_Life.java:172: class, interface, or enum expected
                            }
                            ^
    user_Life.java:175: class, interface, or enum expected
                    for (int row=0; row<18; row++)
                                    ^
    user_Life.java:175: class, interface, or enum expected
                    for (int row=0; row<18; row++)
                                            ^
    user_Life.java:177: class, interface, or enum expected
                            for (int col=0; col<18; col++)
                                            ^
    user_Life.java:177: class, interface, or enum expected
                            for (int col=0; col<18; col++)
                                                    ^
    user_Life.java:180: class, interface, or enum expected
                            }
                            ^
    user_Life.java:184: class, interface, or enum expected
    public static int countNeighbors ( final boolean[][] board, final int row, final int col )
                  ^
    user_Life.java:184: class, interface, or enum expected
    public static int countNeighbors ( final boolean[][] board, final int row, final int col )
                                             ^
    user_Life.java:184: class, interface, or enum expected
    public static int countNeighbors ( final boolean[][] board, final int row, final int col )
                                                                      ^
    user_Life.java:184: class, interface, or enum expected
    public static int countNeighbors ( final boolean[][] board, final int row, final int col )
                                                                                     ^
    user_Life.java:187: class, interface, or enum expected
    for (int r=row-1; r<= row+1; r++)
    ^
    user_Life.java:187: class, interface, or enum expected
    for (int r=row-1; r<= row+1; r++)
                      ^
    user_Life.java:187: class, interface, or enum expected
    for (int r=row-1; r<= row+1; r++)
                                 ^
    user_Life.java:192: class, interface, or enum expected
            }
            ^
    user_Life.java:193: class, interface, or enum expected
            for (int c=col-1; c<=col+1; c++)
                              ^
    user_Life.java:193: class, interface, or enum expected
            for (int c=col-1; c<=col+1; c++)
                                        ^
    user_Life.java:198: class, interface, or enum expected
                    }
                    ^
    user_Life.java:202: class, interface, or enum expected
                    }
                    ^
    user_Life.java:207: class, interface, or enum expected
    }
    ^
    62 errors


  2. #2
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,320
    Thanks
    181
    Thanked 833 Times in 772 Posts
    Blog Entries
    5

    Default Re: Why am I getting 62 errors?

    Check your brackets (runaway errors like this are many times the result of non-complementary bracketing which makes the compiler scream)...most notably in the else near the "//Set up Random". This isn't the only error, but the one which is giving you the majority of them.

  3. #3
    Junior Member
    Join Date
    Dec 2008
    Posts
    11
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Why am I getting 62 errors?

    okay that basically took care of 61 errors and I have one left

    its saying:

    user_Life.java:195: illegal start of expression
    if(col<=||col>=GRIDSIZE||(r==row && c==col))
    ^
    1 error

  4. #4
    Member Charlie's Avatar
    Join Date
    Jun 2010
    Location
    Sweden
    Posts
    41
    Thanks
    1
    Thanked 5 Times in 5 Posts

    Default Re: Why am I getting 62 errors?

    if(col<= INPUT SOMETHING HERE ||col>=GRIDSIZE||(r==row && c==col))

    You have to input something to test for here. if(col <= || col >= GRIDSIZE) doesnt work.

  5. #5
    Member
    Join Date
    Jan 2010
    Posts
    42
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Default Re: Why am I getting 62 errors?

    i can help if you got 69 errors

Similar Threads

  1. not spelling errors
    By britishgoose01 in forum What's Wrong With My Code?
    Replies: 1
    Last Post: April 28th, 2010, 08:59 PM
  2. Exception Errors
    By TIMBERings in forum Exceptions
    Replies: 1
    Last Post: December 10th, 2009, 02:13 AM
  3. Errors with LispList
    By Newoor in forum Collections and Generics
    Replies: 10
    Last Post: October 25th, 2009, 04:25 PM
  4. [SOLVED] Error of "cannot find symbol"
    By big_c in forum File I/O & Other I/O Streams
    Replies: 31
    Last Post: April 9th, 2009, 11:20 AM
  5. Ambiguity and non-static variable reference error in java
    By jenseits in forum AWT / Java Swing
    Replies: 5
    Last Post: December 8th, 2008, 07:04 PM