Reduce the reproductive rate of a rabbit with age

From TRCCompSci - AQA Computer Science
Jump to: navigation, search

Set method

there is already a get method for the ReproductionRate, but none for the set. Add the nethod below into the Rabbit class:

1 public void SetReproductionRate(double value)
2 {
3 	ReproductionRate = value;
4 }

Set value by age

The Warren class has an AgeRabbits method, after the code to calculate the age add the code to reduce the ReproductionRate:

 1 private void AgeRabbits(bool ShowDetail)
 2 {
 3 	int DeathCount = 0;
 4 	for (int r = 0; r < RabbitCount; r++)
 5 	{
 6 		Rabbits[r].CalculateNewAge();
 7 
 8                 //Added this line
 9 		Rabbits[r].SetReproductionRate(Rabbits[r].GetReproductionRate() - 0.1);
10 
11 		if (Rabbits[r].CheckIfDead())
12 		{
13 			Rabbits[r] = null;
14 			DeathCount++;
15 		}
16 	}
17 	CompressRabbitList(DeathCount);
18 	if (ShowDetail)
19 	{
20 		Console.WriteLine("  " + DeathCount + " rabbits die of old age.");
21 	}
22 }

Display value

The inspect method of the Rabbit class already displays the ReproductionRate, so no more coding is required.