I have this code and I am trying to have my on_path method reference the variable first but the compiler says cannot find. I have it declared not sure why its not recognized?

public class hmwkr6
{
  private static final int size = 5;
  private static final int wall = 1;
  private static int open = 0;
  private static int[][] walls = {
    {0, 0, 0, 0, 0},
    {1, 1, 0, 1, 1},
    {1, 1, 0, 1, 1},
    {0, 0, 0, 0, 0},
    {0, 1, 1, 1, 0}};
  private final int dest_row = 4;
  private final int dest_col = 0;
  
  class square
  {
    int row;
    int col;
    square(int row1, int col1)
    {
      row = row1;
      col = col1;
    }
  
   class path
  {
    square first;
    path rest;
    path(square first1, path rest1)
    {
      first = first1;
      rest = rest1;
    }
  
   
  public boolean on_path(square sq1, path p)
  {
  for(int i = 0; i<walls.length; i++)
  {
    if(square.first==0)
    {
      return true;
    }
    if(square.first==1)
    {
      return false;
    }
    else{}
      
  }//end while
    }//end method
   }
  }
}

You have "first" defined as a member of the "path" class, not of the "square" class. Also, you are using the class name, rather than the parameter name, in your on_path() method.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.