Difference between revisions of "Create a giant warren which allows 200 rabbits"

From TRCCompSci - AQA Computer Science
Jump to: navigation, search
Line 1: Line 1:
 
Before you can use the Warren class as the parent of the SuperWarren class you may need to create another constructor class. You will need to create one which doesn't accept any values, the other 2 constructor must have parameters passed:
 
Before you can use the Warren class as the parent of the SuperWarren class you may need to create another constructor class. You will need to create one which doesn't accept any values, the other 2 constructor must have parameters passed:
  
</syntaxhighlight>
+
<syntaxhighlight lang=csharp>
 
     public Warren()
 
     public Warren()
 
     {
 
     {
Line 16: Line 16:
 
Because we want to override the inspect method in the new class, you need to change the Inspect method to virtual:
 
Because we want to override the inspect method in the new class, you need to change the Inspect method to virtual:
  
</syntaxhighlight>
+
<syntaxhighlight lang=csharp>
 
     public virtual void Inspect()
 
     public virtual void Inspect()
 
     {
 
     {

Revision as of 09:55, 24 May 2017

Before you can use the Warren class as the parent of the SuperWarren class you may need to create another constructor class. You will need to create one which doesn't accept any values, the other 2 constructor must have parameters passed:

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

Because we want to override the inspect method in the new class, you need to change the Inspect method to virtual:

    public virtual void Inspect()
    {
      Console.WriteLine("Periods Run " + PeriodsRun + " Size " + RabbitCount);
    }