OK..First of all I have to admit that I get the feeling that you have not spent enough time analysing the problem and preparing the design for your application. Most people tend to jump into coding without a proper design in mind and that it is the cause of many problems in my opinion.
So looking at all posts you have made so far I can give you the following guidelines.
1. There is definitely a class called 'Creeper'. A creeper has an age and a weight. So the Creeper class should have two integer attributes, namely age and weight. Methods should be provided to get and set these two attributes.
public class Creeper {
private int weight;
private int age;
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
public int getWeight() {
return weight;
}
public void setWeight(int weight) {
this.weight = weight;
}
}
2. There should be a class called 'Cell'. Each cell has a number of creepers so the Cell class should have an array of Creepers. Note the following line in the pseudo code.
//check for food
//if there is food in the cell :i'm guessing amount of food is just a var.
//to store any changes to initialFood from Class one
Universe amountOfFood = new Universe();
Clearly amountOfFood is a variable of type 'Universe'. (I hope your program have a class called Universe which probably has an integer attribute called initialFood. The getInitialFood() method simply returns this value. There also should be a setter method because we want to change the value while feeding the creepers) Then there is no need to put the amount of food attribute in the Cell class.
3. The number of creepers in a cell may vary as new creepers are created while feeding. Then we can't use a simple array in the Cell class to hold creepers. We have to use something like an array list where the number of objects is not limited.
import java.util.ArrayList;
public class Cell
{
private ArrayList<Creeper> creepers=new ArrayList<Creeper>();//the array within a cell (I assumed the size to be 10)
/*
* This method creates a new creeper and adds it to the arraylist
*/
public void addCreeper(int weight, int age)
{
Creeper C=new Creeper();
C.setAge(age);
C.setWeight(weight);
creepers.add(C);
}
public void feedCreepers()
{
Universe U=new Universe();
for (int index=0; index<creepers.size(); index++)
{
int food=U.getInitialFood();
if (food!=0)
{
//Now feed the right amount of food to the creeper (just use the setWeight() method)
//Set the new initialFood value in the Universe class
//Check for maximum weight and create a new creeper if needed (call addCreeper() method)
}
}
}
/*
* This method accepts a weight value and assigns it as the weight of all the creepers
*/
public void setWieghts(int weight)
{
for (int index=0; index<creepers.size(); index++)
{
creepers.get(index).setWeight(weight);
}
}
/*
* This method accepts an age value and assigns it as the age of all the creepers
*/
public void setAges(int age)
{
for (int index=0; index<creepers.size(); index++)
{
creepers.get(index).setWeight(age);
}
}
}
4. You may use any other methods as required to extend the features of the classes.
5. You may do something like the following in the One class.
public class One{
private Cell[] cells = new Cell[9];
public void BigBang()
{
initializeWeights();
initializeAges();
}
/*
* Sets the weight of all the creepers in all the cells
*/
private void initializeWeights()
{
for (int i=0; i<cells.length; i++)
{
int weight= (int) (Math.random() * 9); //Generate values as you need
cells[i].setWieghts(weight);
}
}
/*
* Sets the age of the creepres in all the cells
*/
private void initializeAges()
{
for (int i=0; i<cells.length; i++)
{
int age= (int) (Math.random() * 9); //Generate values as you nees
cells[i].setWieghts(age);
}
}
}
Hope this helps
Regards,
Hiranya