Monday, 9 September 2013

How and Where should I add the main method to run?

How and Where should I add the main method to run?

So i feel as if the code is complete and ready to run, but I am having
trouble with the basics and completely forgot where to put the main method
and what to put in it. My class is called "Cell" and has a few methods and
such in it, now i want to run it, sorry if i didnt give enough details,
hopefully you all will understand. CODE:
public class Cell {
//We need an array for the cells and one for the rules.
public int[] cells = new int[9];
public int[] ruleset = {0,1,0,1,1,0,1,0};
//Compute the next generation.
public void generate()
{
//All cells start with state 0, except the center cell has state 1.
for (int i = 0; i < cells.length; i++)
{
cells[i] = 0;
}
cells[cells.length/2] = 1;
int[] nextgen = new int[cells.length];
for (int i = 1; i < cells.length-1; i++)
{
int left = cells[i-1];
int me = cells[i];
int right = cells[i+1];
nextgen[i] = rules(left, me, right);
}
cells = nextgen;
}
//Look up a new state from the ruleset.
public int rules (int a, int b, int c)
{
if (a == 1 && b == 1 && c == 1) return ruleset[0];
else if (a == 1 && b == 1 && c == 0) return ruleset[1];
else if (a == 1 && b == 0 && c == 1) return ruleset[2];
else if (a == 1 && b == 0 && c == 0) return ruleset[3];
else if (a == 0 && b == 1 && c == 1) return ruleset[4];
else if (a == 0 && b == 1 && c == 0) return ruleset[5];
else if (a == 0 && b == 0 && c == 1) return ruleset[6];
else if (a == 0 && b == 0 && c == 0) return ruleset[7];
return 0;
}{
}
}

No comments:

Post a Comment