Quantcast
Channel: Programming Forums
Viewing all articles
Browse latest Browse all 51036

cannot find symbol

$
0
0
First time compiling I had about 107 errors. This "cannot find symbol" thing is stumping me though. I looked it up from about.com/java and it might be because:
"trying to use a variable without declaring it.
misspelling a class or method name (remember, Java is case sensitive).
the parameters used do not match a method's signature.
the packaged class has not being referenced correctly using an import declaration."
I can't for the life--ha that's funny--figure it out.

Any help would be appreciated. Thanks!



error: cannot find symbol
genNextGrid(board);
^
symbol: method genNextGrid(boolean[][])
location: class prog19_Life
prog19_Life.java:135: error: cannot find symbol
for(int r = 0; r < grid.length; r++)
^
symbol: variable grid
location: class prog19_Life
prog19_Life.java:137: error: cannot find symbol
for(int c = 0; c < grid[r].length; c++)
^
symbol: variable grid
location: class prog19_Life
prog19_Life.java:139: error: cannot find symbol
z = countNeighbors (grid, r, c);
^
symbol: variable grid
location: class prog19_Life
prog19_Life.java:140: error: cannot find symbol
if(grid[r][c] == true)
^
symbol: variable grid
location: class prog19_Life
prog19_Life.java:147: error: cannot find symbol
if(grid[r][c] == false)
^
symbol: variable grid
location: class prog19_Life
prog19_Life.java:154: error: cannot find symbol
for(int r = 0; r < grid.length; r++)
^
symbol: variable grid
location: class prog19_Life
prog19_Life.java:156: error: cannot find symbol
for(int c = 0; c < grid.length; c++)
^
symbol: variable grid
location: class prog19_Life
prog19_Life.java:158: error: cannot find symbol
grid[r][c]=temp[r][c];
^
symbol: variable grid
location: class prog19_Life



public class prog19_Life
{

    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' )
        {
            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' )
        {
            
            board [17][0] = true; board[16][1] = true; board[15][1] = true;
            board[16][2] = true;
            board [17][2] = true;
        }
        else
        {
            
            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.printf ( "%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();
        }
    }


    
    public static void clearGrid ( boolean[][] grid )
    { for(int r = 0; r< grid.length; r++){
	 for(int c = 0; c < grid[r].length; c++) {
            grid [r] [c] = false;
        }
    }
    }
 
    {
    boolean [][] temp = new boolean [GRIDSIZE][GRIDSIZE];
      int x=  0;
      int z=  0;
      for(int r = 0; r < grid.length; r++)
        {
            for(int c = 0; c < grid[r].length; c++)
            {
                z = countNeighbors (grid, r, c);
            if(grid[r][c] == true)
            {
              if(z == 2 || z == 3)
                 temp[r][c] = false;
                 else
                    temp[r][c] = false;
            }
            if(grid[r][c] == false)
                    if(z == 3)
                    {
                        temp [r][c] = true;
                    }
            }
        }
            for(int r = 0; r < grid.length; r++)
            {
            for(int c = 0; c < grid.length; c++)
            {
            grid[r][c]=temp[r][c];
            }
            }
    }


    public static int countNeighbors ( final boolean[][] grid, final int row, final int col)
    {
    int z = 0;
                                                           
  int x = 0;
    int y = 0;
    boolean [][] board = new boolean [GRIDSIZE][GRIDSIZE];
            x = col;
            y = row;
            board[y][x]=grid[y][x];
                if( y== 0&& x == 0)
                {
                    if(board[y+1][x] == true)
                        z++;
                    if(board[y][x+1] == true)
                        z++;
                    if(board[y+1][x+1] == true)
                        z++;
                }
                if( y== 0&& x == 17)
                {
                    if(board[y][x-1] == true)
                        z++;
                    if(board[y+1][x-1] == true)
                        z++;
                    if(board[y+1][x] == true)
                        z++;
                }
                 if( y== 17&& x== 0)
                {
                    if(board[y-1][x] == true)
                        z++;
                    if(board[y-1][x+1] == true)
                        z++;
                    if(board[y][x+1] == true)
                        z++;
                }
             if( y== 17&& x== 17)
                {
                    if(board[y][x-1] == true)
                        z++;
                    if(board[y-1][x-1] == true)
                        z++;
                    if(board[y-1][x] == true)
                        z++;
                }
             if(y == 0)
             {
			   if(x != 0 && x != 17)
                 {
                     if(board[y][x-1] == true)
                         z++;
                     if(board[y+1][x-1] == true)
                         z++;
                     if(board[y+1][x] == true)
                         z++;
                     if(board[y+1][x+1] == true)
                         z++;
                     if(board[y][x+1] == true)
                         z++;
                 }
             }
                if(y == 17)
             {
                 if(x != 0 && x != 17)
                 {
                     if(board[y][x-1] == true)
                         z++;
                     if(board[y-1][x-1] == true)
                         z++;
                     if(board[y-1][x] == true)
                         z++;
                     if(board[y-1][x+1] == true)
                         z++;
                     if(board[y][x+1] == true)
                         z++;
                 }
             }
            if(x == 0)
             {
                 if(y != 0 && y != 17)
                 {
                     if(board[y-1][x] == true)
                         z++;
                     if(board[y-1][x+1] == true)
                         z++;
                     if(board[y][x+1] == true)
                         z++;
                     if(board[y+1][x+1] == true)
                         z++;
                     if(board[y+1][x] == true)
                         z++;
                                                           
 }
             }
             if(x == 17)
             {
                 if(y != 0 && y != 17)
                 {
                     if(board[y-1][x] == true)
                         z++;
                     if(board[y-1][x-1] == true)
                         z++;
                     if(board[y][x-1] == true)
                         z++;
                     if(board[y+1][x-1] == true)
                         z++;
                     if(board[y+1][x] == true)
                         z++;
                 }
             }
             if(y != 0 && y != 17)
             {
                 if(x != 0 && x != 17)
                 {    if(board[y-1][x-1] == true)
                         z++;
                     if(board[y-1][x] == true)
                         z++;
                     if(board[y-1][x+1] == true)
                         z++;
                     if(board[y][x-1] == true)
                         z++;
                     if(board[y][x+1] == true)
                         z++;
                     if(board[y+1][x-1] == true)
                         z++;
                     if(board[y+1][x]== true)
                         z++;
                     if(board[y+1][x+1] == true)
                         z++;
                 }
             }
             return z;
    }}                                               


Viewing all articles
Browse latest Browse all 51036

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>