Difference between revisions of "Arrays - 2017"

From TRCCompSci - AQA Computer Science
Jump to: navigation, search
Line 4: Line 4:
 
   {
 
   {
 
     private const int MaxRabbitsInWarren = 99;
 
     private const int MaxRabbitsInWarren = 99;
     private Rabbit[] Rabbits;
+
     '''private Rabbit[] Rabbits;'''
 
     private int RabbitCount = 0;
 
     private int RabbitCount = 0;
 
     private int PeriodsRun = 0;
 
     private int PeriodsRun = 0;
Line 14: Line 14:
 
     {
 
     {
 
       this.Variability = Variability;
 
       this.Variability = Variability;
       Rabbits = new Rabbit[MaxRabbitsInWarren];
+
       '''Rabbits = new Rabbit[MaxRabbitsInWarren];'''
 
       RabbitCount = (int)(CalculateRandomValue((int)(MaxRabbitsInWarren / 4), this.Variability));
 
       RabbitCount = (int)(CalculateRandomValue((int)(MaxRabbitsInWarren / 4), this.Variability));
 
       for (int r = 0; r < RabbitCount; r++)
 
       for (int r = 0; r < RabbitCount; r++)
 
       {
 
       {
         Rabbits[r] = new Rabbit(Variability);
+
         '''Rabbits[r] = new Rabbit(Variability);'''
 
       }
 
       }
 
     }
 
     }
Line 26: Line 26:
 
       this.Variability = Variability;
 
       this.Variability = Variability;
 
       this.RabbitCount = rabbitCount;
 
       this.RabbitCount = rabbitCount;
       Rabbits = new Rabbit[MaxRabbitsInWarren];
+
       '''Rabbits = new Rabbit[MaxRabbitsInWarren];'''
 
       for (int r = 0; r < RabbitCount; r++)
 
       for (int r = 0; r < RabbitCount; r++)
 
       {
 
       {
         Rabbits[r] = new Rabbit(Variability);
+
         '''Rabbits[r] = new Rabbit(Variability);'''
 
       }
 
       }
 
     }
 
     }
 
   }
 
   }
 
</syntaxhighlight>
 
</syntaxhighlight>

Revision as of 15:01, 6 February 2017

An array is a list consisting of one and only one data type, such as string or int. Each element in an array is assigned an integer subscript as an order to the list for when each element has been added.

 1   class Warren
 2   {
 3     private const int MaxRabbitsInWarren = 99;
 4     '''private Rabbit[] Rabbits;'''
 5     private int RabbitCount = 0;
 6     private int PeriodsRun = 0;
 7     private bool AlreadySpread = false;
 8     private int Variability;
 9     private static Random Rnd = new Random();
10 
11     public Warren(int Variability)
12     {
13       this.Variability = Variability;
14       '''Rabbits = new Rabbit[MaxRabbitsInWarren];'''
15       RabbitCount = (int)(CalculateRandomValue((int)(MaxRabbitsInWarren / 4), this.Variability));
16       for (int r = 0; r < RabbitCount; r++)
17       {
18         '''Rabbits[r] = new Rabbit(Variability);'''
19       }
20     }
21 
22     public Warren(int Variability, int rabbitCount)
23     {
24       this.Variability = Variability;
25       this.RabbitCount = rabbitCount;
26       '''Rabbits = new Rabbit[MaxRabbitsInWarren];'''
27       for (int r = 0; r < RabbitCount; r++)
28       {
29         '''Rabbits[r] = new Rabbit(Variability);'''
30       }
31     }
32   }