wood burning stoves 2.0*
The moose likes Beginning Java and the fly likes Trouble with symbols not being found. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Trouble with symbols not being found." Watch "Trouble with symbols not being found." New topic
Author

Trouble with symbols not being found.

Ian E Jones
Greenhorn

Joined: Nov 08, 2010
Posts: 4
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

Joined: Oct 23, 2009
Posts: 150

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


star chaser..
Stephan van Hulst
Bartender

Joined: Sep 20, 2010
Posts: 3615
    
  14

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

Joined: Nov 08, 2010
Posts: 4


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

Joined: Sep 20, 2010
Posts: 3615
    
  14

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

Joined: Sep 20, 2010
Posts: 3615
    
  14

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

Joined: Nov 08, 2010
Posts: 4
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

Joined: Sep 20, 2010
Posts: 3615
    
  14

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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Trouble with symbols not being found.