Allow the capacity of a warren to vary, some warrens may be smaller and other may be larger

From TRCCompSci - AQA Computer Science
Revision as of 10:58, 8 June 2017 by Admin (talk | contribs) (Created page with "Within the warren class, a variable called MaxRabbitsInWarren is set to 99. The const declaration means it can't be changed during runtime. You must therefore remove the const...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

Within the warren class, a variable called MaxRabbitsInWarren is set to 99. The const declaration means it can't be changed during runtime. You must therefore remove the const:

private const int MaxRabbitsInWarren = 99;

Becomes:

private int MaxRabbitsInWarren = 99;

Warren Constructors

ublic Warren(int Variability)
    {
      this.Variability = Variability;
      Rabbits = new Rabbit[MaxRabbitsInWarren];
      RabbitCount = (int)(CalculateRandomValue((int)(MaxRabbitsInWarren / 4), this.Variability));
      for (int r = 0; r < RabbitCount; r++)
      {
        Rabbits[r] = new Rabbit(Variability);
      }
    }

    public Warren(int Variability, int rabbitCount)
    {
      this.Variability = Variability;
      this.RabbitCount = rabbitCount;
      Rabbits = new Rabbit[MaxRabbitsInWarren];
      for (int r = 0; r < RabbitCount; r++)
      {
        Rabbits[r] = new Rabbit(Variability);
      }
    }