Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Trouble with symbols not being found.

 
Ian E Jones
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, I'm having some trouble implementing Conway's game of life. I can get to grips with the rules, but variable names are causing me headaches.

Here's how I have the code:



My problem is in the next method at the bottom. I am getting a bunch of errors at compile time relating to variables and missing symbols.

Can anyone help me fix this? I know it's probably something simple but i'm new to this so I can't figure it out.

Thanks in advance!
 
Gary Ba
Ranch Hand
Posts: 161
Firefox Browser Java Windows
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Where did you declare size? And colspace++ is not the same as col++ (also applies to others).

And please post the compile errors. It's easier to look at the compile error and refer back to the code.

good luck,
Gary
 
Stephan van Hulst
Bartender
Pie
Posts: 6083
71
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Do away with the declaration of readgrid, and the assignment of generation to it. First of all, generation is not declared in the scope of next(), and secondly I doubt you would need readgrid because you already have access to cells.
 
Ian E Jones
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


Those are the errors. I declared size on line 7, is there something else I should be doing at the end with that variable?
 
Stephan van Hulst
Bartender
Pie
Posts: 6083
71
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Neither size nor generation are declared within the scope of the next method. They are local to the main method, and the Life constructor.

I already told you what to do about the generation symbol. Replace size in your next method with cells.length, and cells[row].length.
 
Stephan van Hulst
Bartender
Pie
Posts: 6083
71
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Also, I notice you assign new columns to the cells array in your next method. Don't do this. First construct the array newGrid with the same dimensions as cells, then read all the data you want from cells, and apply the results to newGrid. Finally when you are done, assign newGrid to cells. This will assure that you don't change the old situation before you are done reading from it.
 
Ian E Jones
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That's actually what I was trying to do, I was just coming up with errors trying to write it any different way, what should I be doing here?
 
Stephan van Hulst
Bartender
Pie
Posts: 6083
71
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If I may make a suggestion, start like this, it should make the next method easier to implement, and the Life class easier to use by another class in general:
Make sure the next() method does not change the state of the current object.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic