I was given the assignment to show the population growth of rabbits per month (method), given the 3 variables, one variable for a newborn rabbit, one for a month old rabbit (which can give birth to a pair), and adults. I am uncertain what the syntax would be for calculating the age progression inside the wait method (per month)? Here was my assignment: - Suppose a newly-born pair of rabbits, one male, one female, are put in a field. Rabbits are able to mate at the age of one month so that at the end of its second month a female can produce another pair of rabbits. Suppose that our rabbits never die and that the female always produces one new pair (one male, one female) every month from the second month on. How many pairs will there be in ten months?
So here was my thought process. The waiting method (month method) in its own class is called 10 times from the main. When called, the newborn babies equal the month babies (they grow up to month babies) and the month babies equal the adults (they grow up to adults) at here, the newborn equals the adults.
public RabbitPopulation()
{ // Just a constructor to initialize instance variables
Newborns = 1;
MonthBabies = 0;
Adults = 0;
NewbornTemp = Newborns;
MonthBabiesTemp = MonthBabies;
AdultsTemp = Adults;
Counter = 0;
}
public void MonthWait()
{
MonthBabies = Newborns;
MonthBabies -= MonthBabiesTemp;
MonthBabiesTemp = MonthBabies;
Adults += MonthBabies;
Newborns = Adults;
}
// in the main program....\\
int i = 0;
RabbitPopulation Rabbits = new RabbitPopulation();
while (i < 10)
{
i += 1;
Rabbits.getPairs(i);
Rabbits.MonthWait();
}
I should end up with a result of 89 rabbits after 10 months. However, I end up with 81 and a rabbit dies within the third-month :p (which is not intended, no rabbits die in this assignment). Please note I am a beginner at C#, don't batter me please