I have 2 classes, Species and CircleofLife
in CircleofLife, I have created several new Species objects like so
Species cat = new Species("Felid", 20, 1.84);
Species human = new Species("Homo Sapiens", 1500, 1.1);
Species amoeba = new Species("Amoeba", 2000000000, 20);
Species bacteria = new Species("bacteria", 20000000,20);
Now, I have a method in Species called kill which sets the population and growth rate values to 0. I am looking for a way to dynamically create an array that I can iterate over using code like this:
for(Species species : circleOfDeath)
{
species.kill;
}
this is approximately what I would like to have happen.
get all objects of type Species.
create an array of type Species[]
add all objects of type Species to the array.
I could just manually create the array, but then I have more work if I want to add more species, and especially if I were to use a for loop to import data and create species off of that data.