Hello all,
This is a very simplistic simulation but i'm hoping to show bacterial growth using this simple piece of code.
public class Bacteria
{
boolean living;
Bacteria x;
int population;
public void spawn()
{
living = true;
try{
Thread.sleep(2000);
}
catch (InterruptedException e )
{}
Fission();
try{
Thread.sleep(100000);
}
catch (InterruptedException e )
{}
Die();
}
private void Fission()
{
x = new Bacteria();
x.spawn();
}
private void Die(){living = false;}
private boolean Check(){return this.living;}
private boolean ping(){return x.Check();}
}
The idea is that if i initialize one object of the Bacteria class and run the spawn() module then it will just continue to "reproduce". The class that is going to run this code needs to be able to keep count of the population of bacteria. I want to represent the population graphically using dashes to represent individual bacteria. My problem is that i cannot see a way to keep count. I was thinking of using something like the ping() module which basically just checks the "next" bacteria and returns a boolean. My problem is i cannot refer to all of the objects within the initial Bacteria object in any sort of efficient manner.
Does anyone have any ideas? I know this could probably be achieved without objects... But I just think this a very elegant design (aside from not being functional).
Thanks for lookin,
Khodeir