Difference between revisions of "Make the probability of a rabbit dying increase with age, ie extra 5% per term"
Line 24: | Line 24: | ||
// Added the line below | // Added the line below | ||
Rabbits[r].setProbabilityOfDeathOtherCauses(Rabbits[r].GetProbabilityOfDeathOtherCauses() + .05); | Rabbits[r].setProbabilityOfDeathOtherCauses(Rabbits[r].GetProbabilityOfDeathOtherCauses() + .05); | ||
− | if (Rabbits[r].CheckIfDead()) | + | |
+ | if (Rabbits[r].CheckIfDead()) | ||
{ | { | ||
Rabbits[r] = null; | Rabbits[r] = null; |
Revision as of 21:26, 13 February 2017
Within the rabbit class, add the following methods to set and get ProbalilityOfDeathOtherCauses:
1 public double GetProbabilityOfDeathOtherCauses()
2 {
3 return ProbabilityOfDeathOtherCauses;
4 }
5
6 public void setProbabilityOfDeathOtherCauses(double value)
7 {
8 ProbabilityOfDeathOtherCauses=value;
9 }
the code below is contained within the Warren Class:
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 // Added the line below
8 Rabbits[r].setProbabilityOfDeathOtherCauses(Rabbits[r].GetProbabilityOfDeathOtherCauses() + .05);
9
10 if (Rabbits[r].CheckIfDead())
11 {
12 Rabbits[r] = null;
13 DeathCount++;
14 }
15 }
16 CompressRabbitList(DeathCount);
17 if (ShowDetail)
18 {
19 Console.WriteLine(" " + DeathCount + " rabbits die of old age.");
20 }
21 }