Difference between revisions of "Reduce the reproductive rate of a rabbit with age"
(→Set value by age) |
|||
(One intermediate revision by the same user not shown) | |||
Line 21: | Line 21: | ||
//Added this line | //Added this line | ||
− | Rabbits[r].SetReproductionRate(Rabbits[r].GetReproductionRate() - . | + | Rabbits[r].SetReproductionRate(Rabbits[r].GetReproductionRate() - 0.1); |
if (Rabbits[r].CheckIfDead()) | if (Rabbits[r].CheckIfDead()) | ||
Line 36: | Line 36: | ||
} | } | ||
</syntaxhighlight> | </syntaxhighlight> | ||
+ | |||
+ | ==Display value== | ||
+ | The inspect method of the Rabbit class already displays the ReproductionRate, so no more coding is required. |
Latest revision as of 21:54, 13 February 2017
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.