A-level Computing/AQA/Paper 1/Skeleton program/2017

From Wikibooks, open books for an open world
Jump to: navigation, search

This is for the new Computer Science Specification. Keep in mind that there is another Comp1 exam for Computing (for retakes?) though this specific page is for the new course.

This is where suggestions can be made about what some of the questions might be and how can we solve them.

Please be respectful and do not vandalise or tamper with the page, as this would affect students' preparation for their exams!

Contents

Add a way for a disease to kill rabbits in warrens.[edit]

Storm or fire affects number of animals in a certain radius.[edit]

C# Solution:

Answer :

Answer :

        private void AdvanceTimePeriod()
        {
            int NewFoxCount = 0;
            if (ShowDetail)
            {
                Console.WriteLine();
            }
            //Start of Fire//
            if (Rnd.Next(1, 5) <= 2)
            {
                int x, y;
                int PercentageToKill = 33;
                int radius = 2;
                x = Rnd.Next(0, LandscapeSize);
                y = Rnd.Next(0, LandscapeSize);
                Console.WriteLine("Fire at (" + x + "," + y + ")");
                for (int Xco = x - radius; Xco <= x + radius; Xco++)
                {
                    for (int Yco = y - radius; Yco <= y + radius; Yco++)
                    {
                        try {
                            if (Landscape[Xco, Yco].Warren != null)
                            {
                                int RabbitsToKill = Landscape[Xco, Yco].Warren.GetRabbitCount() * PercentageToKill / 100;
                                Landscape[Xco, Yco].Warren.EatRabbits(RabbitsToKill);
                                if (ShowDetail)
                                {
                                    Console.WriteLine(PercentageToKill + "% rabbits killed in Warren at (" + Xco + "," + Yco + ")");
                                }
                            }
                        }
                        catch { }
                    }
                }
            }
            //End of Fire//

Delphi/Pascal Solution

Answer :

Answer :

//Start of Fire
    if (Random(20) <= 2) then
    begin
      FRadius := Random(5);
      PercentToKill := Random(100);
      xFire := Random(LandscapeSize);
      yFire := Random(LandscapeSize);

      Writeln('A fire has occured at (', XFire,',', YFire,')');

      for Xco := (xFire - FRadius) to (xFire + FRadius) do
        Begin
          for Yco := (yFire - FRadius) to (yFire + FRadius) do
            begin
            try
              begin
                if not(Landscape[Xco][Yco].Warren = nil) then
                  begin
                    RabbitsToKill := Round(Landscape[Xco][Yco].Warren.GetRabbitCount() * PercentToKill / 100);
                    Landscape[Xco][Yco].Warren.EatRabbits(RabbitsToKill);
                    
                    if (ShowDetail) then
                      Writeln(RabbitsToKill, ' have died in the fire at (', Xco, ',', Yco, ')');
                  end;
              end;
            except
            end;
          end;
        end;
      end;
//End of Fire

//Harry Barron, Faringdon Community College

Java Solution

Answer :

Answer :

This method needs to be called from somewhere. I added an option in the simulation menu to execute the storm code. If you call the storm via the menu like I did, then other factors such as the rabbits dying from natural causes and being eaten still happen for the warrens affected.

    private void StormLocation(){
        int locationX = Rnd.nextInt(LandscapeSize);
        int locationY = Rnd.nextInt(LandscapeSize);
        int radius = 5;
        System.out.println("Storm At: "+locationX+","+locationY + ", Radius:" + radius);
        for(int LocCentreY = locationY-(int) Math.floor(radius/2), endpoint = locationY+(int) Math.floor(radius/2); LocCentreY < endpoint+1; LocCentreY++){
            if(LocCentreY > 0 && LocCentreY < LandscapeSize){
                for(int LocCentreX = locationX-(int) Math.floor(radius/2), endpointX = locationX+(int) Math.floor(radius/2); LocCentreX < endpointX+1; LocCentreX++){
                    if(LocCentreX > 0 && LocCentreX < LandscapeSize){

                        if(Landscape[LocCentreX][LocCentreY].Warren != null){
                            int percentage = Rnd.nextInt(100);
                            int rabbitCount = Landscape[LocCentreX][LocCentreY].Warren.GetRabbitCount();
                            int rabbitcountnew = rabbitCount * percentage/100;
                            Landscape[LocCentreX][LocCentreY].Warren.EatRabbits(rabbitCount-rabbitcountnew);
                            System.out.println("Warren At "+LocCentreX+","+LocCentreY+" Was hit by the storm, lowering the rabbit count from "+rabbitCount+" to "+ rabbitcountnew);

                        }
                    }
                }
            }
        }
    }
// Joel LB, Twyford Sixth Form

Python Solution:

Answer :

Answer :

"""FIRE TRIGGER BASED ON RANDOM CHANCE
          INSERT AT START of AdvanceTimePeriod"""
    if random.randint(1,5) <= 2:
      self.fire(self.__LandscapeSize)

"""FIRE SUBROUTINE"""
  def fire(self, LandscapeSize):
    x = 9#random.randint(0,LandscapeSize)
    y = 5#random.randint(0, LandscapeSize)
    radius = random.randint(1,3)
    PercentageKill = 40
    print(radius, "Fire starts at (" + str(x) + "," + str(y) + ")")

    for xAxis in range(x - radius, x + radius):
      for yAxis in range(y - radius, y + radius):
        if 0 < xAxis < LandscapeSize and 0 < yAxis < LandscapeSize:
          if not self.__Landscape[xAxis][yAxis].Warren is None:
            rabbitDeaths = self.__Landscape[xAxis][yAxis].Warren.GetRabbitCount() * PercentageKill // 100
            self.__Landscape[xAxis][yAxis].Warren.EatRabbits(rabbitDeaths)

            if self.__ShowDetail:
              print(rabbitDeaths, "rabbits have met a grizzly end at (" + str(xAxis) + "," + str(yAxis) + ")")

##Alvise and Matt, Budmouth College

VB.NET Solution

Answer :

Answer :

Private Sub AdvanceTimePeriod()
           Dim num As Integer
           Randomize()
           num = (Rnd.Next(1, 5) <= 2)
           Dim NewFoxCount As Integer = 0
           If ShowDetail Then
               Console.WriteLine()
           End If
           If (num <= 2) Then
               Dim x As Integer
               Dim y As Integer
               Dim percentagetokill As Integer
               Dim radius As Integer
               Dim xco As Integer
               Dim yco As Integer
               Dim Rabbitstokill As Integer
               percentagetokill = 33
               radius = 2
               x = Rnd.Next(0, LandscapeSize)
               y = Rnd.Next(0, LandscapeSize)
               Console.WriteLine("Fire at" & x & "," & y)
               For xco = x - radius To x + radius
                   For yco = y - radius To y + radius
                       If (Landscape(xco, yco).Warren IsNot Nothing) Then
                           Rabbitstokill = (Landscape(xco, yco).Warren.GetRabbitCount()) * (percentagetokill / 100)
                           Landscape(xco, yco).Warren.EatRabbits(Rabbitstokill)
                           If (ShowDetail) Then
                               Console.WriteLine(percentagetokill & "% rabbits killed in warren at" & xco & " " & yco)
                           End If
                       End If
                   Next
               Next
           End If

'JS

Add a way to check if input coordinates are valid[edit]

C# Solution:

Answer :

Answer :

//Written by Charles Batten using Linq for coordinate range chceking
using System.Linq;
private int InputCoordinate(char Coordinatename)
{
   while (true)
   {
      Console.WriteLine("Enter the {0} coordinate:", Coordinatename);
      bool succeeded = Int32.TryParse(Console.ReadLine(), out int coordinate);

      if(succeeded && Enumerable.Range(0, LandscapeSize).Contains(coordinate))
      {
         return coordinate;
      }
      else
      {
         Console.WriteLine("The coordinate you entered was invalid.");
         Console.WriteLine("Please enter an integer between 0 and {0}", (LandscapeSize - 1));
      }
   }
}

//In Response To Luke's Attempt, I attempted to solve the problem and developed the following solution.
        private int InputCoordinate(char Coordinatename)
        {
            bool invalidInput = true;
            int Coordinate = 0;
            Console.Write("  Input " + Coordinatename + " coordinate: ");
            try
            {
                Coordinate = Convert.ToInt32(Console.ReadLine());
                do
                {
                    if (Coordinate > LandscapeSize)
                    {
                        Console.Write("Invalid Input Please Input A Value smaller than " + LandscapeSize + ": ");
                        Coordinate = Convert.ToInt32(Console.ReadLine());
                    }
                }
                while (Coordinate > LandscapeSize);
            }
            catch
            {
                Console.Write("Invalid Input: ");
                while(invalidInput == true)
                {
                    try
                    {
                        Coordinate = Convert.ToInt32(Console.ReadLine());
                        invalidInput = false;
                    }
                    catch
                    {
                     //Continues Loop If Invalid Input
                     invalidInput = true;
                    }
                }
            }
            return Coordinate;
        }
//Declyn Sealey, St Mary's College

//For a better solution:
        private int InputCoordinate(char Coordinatename)
        {
            int Coordinate = 0;
            while (true)
            {
                Console.Write("  Input " + Coordinatename + " coordinate: ");
                try
                {
                    Coordinate = Convert.ToInt32(Console.ReadLine());
                    if (0 <= Coordinate && Coordinate < LandscapeSize)
                    {
                        break;
                    }
                    else
                    {
                        Console.Write("Invalid Input. Try again");
                    }
                }
                catch
                {
                    Console.Write("Invalid Input. Try again");
                }
            }
            return Coordinate;
        }

Delphi/Pascal Solution

Answer :

Answer :

Java Solution

Answer :

Answer :

 private int InputCoordinate(char CoordinateName)
    {
        int Coordinate;
        Coordinate = Console.readInteger("  Input " + CoordinateName + " coordinate: ");
        while ( Coordinate < 0 || Coordinate > LandscapeSize ){
        	Console.println("This coordinate is not on the board, enter again.");
        	Coordinate = Console.readInteger("  Input " + CoordinateName + " coordinate: ");
        }
        return Coordinate;
    }

//This is the alternative solution and works by checking the coordinates for menu options 3 and 4, this is worse but still works:
            if (MenuOption == 3)
            {
                x = InputCoordinate('x');
                y = InputCoordinate('y');
               while ( x > LandscapeSize || x < 0 || y > LandscapeSize || y < 0){// validation
            	   Console.println("Sorry these coordinates are invalid, enter again");
            	   x = InputCoordinate('x');
                   y = InputCoordinate('y');
               }
                if (Landscape[x][y].Fox != null)
                {
                    Landscape[x][y].Fox.Inspect();
                }
               
             	   
            }
            if (MenuOption == 4)
            {
                x = InputCoordinate('x');
                y = InputCoordinate('y');
                while ( x > LandscapeSize || x < 0 || y > LandscapeSize || y < 0){// validation
             	   Console.println("Sorry these coordinates are invalid, enter again");
             	   x = InputCoordinate('x');
                    y = InputCoordinate('y');
                }
                if (Landscape[x][y].Warren != null )
                {
                    Landscape[x][y].Warren.Inspect();
                    ViewRabbits = Console.readLine("View individual rabbits (y/n)?");
                    if ( ViewRabbits.equals("y") )
                    {
                        Landscape[x][y].Warren.ListRabbits();
                    }
                }
            }

Python Solution:

Answer :

Answer :

    def __InputCoordinate(self, CoordinateName):
    error = True
    while error == True:
      try:
        Coordinate = int(raw_input("Input " + CoordinateName + " coordinate: "))
        if Coordinate in range(self.__LandscapeSize):
          error = False
      except:
        pass
      if error == True:
        print "Entry invalid, please re-enter"
    return Coordinate

VB.NET Solution

Answer :

Answer :

    Private Function InputCoordinate(ByVal CoordinateName As Char) As Integer
        Dim Coordinate As Integer
        Do
            Console.Write("  Input " & CoordinateName & " coordinate: ")
            Coordinate = CInt(Console.ReadLine())
            'Checks to see if the Input is within the bounds of the map
        Loop Until Coordinate < LandscapeSize And Coordinate >= 0
        Return Coordinate
    End Function

Display number of rabbits born that period (This can be done if option 2 selected when advancing time period).[edit]

C# Solution:

Answer :

Answer :

Delphi/Pascal Solution

Answer :

Answer :

Java Solution

Answer :

Answer :

Python Solution:

Answer :

Answer :

  """Add NewRabbitsThisPeriod to the start of AdvanceTimePeriod,
  it will reset every time period"""
  NewRabbitsThisPeriod = 0

  """Add Return Babies to the end of MateBabies"""
  Return Babies

  """In AdvanceGeneration Set NewRabbits equal to MateRabbits on the line MateRabbits is currently on. Return NewRabbits at the end of the line"""
  NewRabbits = self.__MateRabbits(ShowDetail)
  Return NewRabbits

  """in AdvanceTimePeriod Add the return Value of AdvanceGeneraton to NewRabbitsThisPeriod. Print if show detail after the the first double for Loop"""
  NewRabbitsThisPeriod += self.__Landscape[x][y].Warren.AdvanceGeneration(self.__ShowDetail)
  if self.__ShowDetail:
  print("New Rabbits Born: " + str(NewRabbitsThisPeriod))
#Jordan, Budmouth College

VB.NET Solution

Answer :

Answer :

Constraints for number of animals placed (when option two is selected).[edit]

C# Solution:

Answer :

Answer :

                   class Program
    {
        static void Main(string[] args)
        {
            Simulation Sim;
            int MenuOption = 0;
            int LandscapeSize;
            int InitialWarrenCount;
            int InitialFoxCount;
            int Variability;
            bool FixedInitialLocations;

            do
            {
                Console.WriteLine("Predator Prey Simulation Main Menu");
                Console.WriteLine();
                Console.WriteLine("1. Run simulation with default settings");
                Console.WriteLine("2. Run simulation with custom settings");
                Console.WriteLine("3. Exit");
                Console.WriteLine();
                Console.Write("Select option: ");
                try
                {
                    MenuOption = Convert.ToInt32(Console.ReadLine());
                }
                catch
                {   bool validInput = false;
                    while(validInput == false)
                    {
                        Console.WriteLine("Invalid Input Please Try Again: ");
                        try
                        {
                            MenuOption = Convert.ToInt32(Console.ReadLine());
                            validInput = true;
                        }
                        catch
                        {
                        }
                    }
                }
                if ((MenuOption == 1) || (MenuOption == 2))
                {
                    if (MenuOption == 1)
                    {
                        LandscapeSize = 15;
                        InitialWarrenCount = 5;
                        InitialFoxCount = 5;
                        Variability = 0;
                        FixedInitialLocations = true;
                    }
                    else
                    {
                        Console.Write("Landscape Size: ");
                        LandscapeSize = Convert.ToInt32(Console.ReadLine());
                        Console.Write("Initial number of warrens: ");
                        InitialWarrenCount = Convert.ToInt32(Console.ReadLine());
                        while (InitialWarrenCount > 10) //Set The Limit as 10 for the InitialWarrenCount however this can be changed.
                        {
                            Console.Write("Too Many Warrens Please Input A Value Less Than 10: ");
                            InitialWarrenCount = Convert.ToInt32(Console.ReadLine());
                        }
                        Console.Write("Initial number of foxes: ");
                        InitialFoxCount = Convert.ToInt32(Console.ReadLine());
                        while(InitialFoxCount > 5) //Set The Limit as 5 for the InitialFoxCount however this can be changed.
                        {
                            Console.Write("Too Many Foxes Please Input A Value Less Than 5: ");
                            InitialFoxCount = Convert.ToInt32(Console.ReadLine());
                        }
                        Console.Write("Randomness variability (percent): ");
                        Variability = Convert.ToInt32(Console.ReadLine());
                        FixedInitialLocations = false;
                    }
                    Sim = new Simulation(LandscapeSize, InitialWarrenCount, InitialFoxCount, Variability, FixedInitialLocations);
                }
            } while (MenuOption != 3);
            Console.ReadKey();
        }
    }//Declyn Sealey, St Marys College

Delphi/Pascal Solution

Answer :

Answer :

Java Solution

Answer :

Answer :

public class Main
{
    public static void main(String[] args) {
        Simulation Sim;
        int MenuOption;
        int LandscapeSize;
        int InitialWarrenCount;
        int InitialFoxCount;
        int Variability;
        Boolean FixedInitialLocations;
        do
        {
            Console.println("Predator Prey Simulation Main Menu");
            Console.println();
            Console.println("1. Run simulation with default settings");
            Console.println("2. Run simulation with custom settings");
            Console.println("3. Exit");
            Console.println();
            MenuOption = Console.readInteger("Select option: ");
            if (MenuOption == 1 || MenuOption == 2)
            {
                if (MenuOption == 1)
                {
                    LandscapeSize = 15;
                    InitialWarrenCount = 5;
                    InitialFoxCount = 5;
                    Variability = 0;
                    FixedInitialLocations = true;
                }
                else
                {   //Added input validation and restrictions on input like the number of inital warrens and foxes cannot be greater than the number of squares and that they have to be positive
                	LandscapeSize=-1;
                    LandscapeSize = Console.readInteger("Landscape Size: ");
                    while(LandscapeSize<0){
                    	Console.println("Please enter a number greater than 0!");
                    	LandscapeSize = Console.readInteger("Landscape Size: ");
                    }
                    
                    InitialWarrenCount=-1;
                    InitialWarrenCount = Console.readInteger("Initial number of warrens: ");
                    while(InitialWarrenCount<0 || InitialWarrenCount>=(LandscapeSize*LandscapeSize)){
                    	Console.println("Please enter a number between 0 and "+(LandscapeSize*LandscapeSize));
                    	InitialWarrenCount = Console.readInteger("Initial number of warrens: ");
                    }
                    
                    InitialFoxCount=-1; 
                    InitialFoxCount = Console.readInteger("Initial number of foxes: ");
                    while(InitialFoxCount<0 || InitialFoxCount>=(LandscapeSize*LandscapeSize)){
                    	Console.println("Please enter a number between 0 and "+(LandscapeSize*LandscapeSize));
                    	InitialFoxCount = Console.readInteger("Initial number of foxes: ");
                    }
                    
                    Variability=-2; 
                    Variability = Console.readInteger("Randomness variability (percent): ");
                    while(Variability<-1||Variability>101){
                    	Console.println("Please enter a number between 0 and 100!");
                    	 Variability = Console.readInteger("Randomness variability (percent): ");
                    }
                    
                    FixedInitialLocations = false;
                }
                Sim = new Simulation(LandscapeSize, InitialWarrenCount, InitialFoxCount, Variability, FixedInitialLocations);
            }
        } while (MenuOption != 3);
        Console.readLine();
    }
} // Gman, Reading School

Python Solution:

Answer :

Answer :

VB.NET Solution

Answer :

Answer :

Display a message when a cell with no fox is selected for fox inspection...Adding a loop too.[edit]

C# Solution:

Answer :

Answer :

public Simulation(int LandscapeSize, int InitialWarrenCount, int InitialFoxCount, int Variability, bool FixedInitialLocations)
        {
            int menuOption;
            int x;
            int y;
            string viewRabbits;
            this.LandscapeSize = LandscapeSize;
            this.Variability = Variability;
            bool animalFound = false; //Bool used to make the search function loop is no animal is found.
            Landscape = new Location[LandscapeSize, LandscapeSize];
            CreateLandscapeAndAnimals(InitialWarrenCount, InitialFoxCount, FixedInitialLocations);
            DrawLandscape();

            do
            {
                Console.WriteLine();
                Console.WriteLine("1. Advance to next time period showing detail");
                Console.WriteLine("2. Advance to next time period hiding detail");
                Console.WriteLine("3. Inspect fox");
                Console.WriteLine("4. Inspect warren");
                Console.WriteLine("5. Exit");
                Console.WriteLine();
                Console.Write("Select option: ");
                menuOption = Convert.ToInt32(Console.ReadLine());

                if (menuOption == 1)
                {
                    TimePeriod++;
                    ShowDetail = true;
                    AdvanceTimePeriod();
                }
                if (menuOption == 2)
                {
                    TimePeriod++;
                    ShowDetail = false;
                    AdvanceTimePeriod();
                }
                if (menuOption == 3)
                {
                    do
                    {
                        x = InputCoordinate('x');
                        y = InputCoordinate('y');
                        if (Landscape[x, y].Fox != null)
                        {
                            animalFound = true; //Exits the loop when a fox has been found.
                            Landscape[x, y].Fox.Inspect();
                        }
                        else
                        {
                            animalFound = false;
                            //Tells the user there is no fox here.
                            Console.WriteLine("No fox found at (" + x + ", " + y + ")");

                            //Just in case they didn't mean to inspect:
                            Console.WriteLine("Would you like to continue the simulation? (y/n)");
                            if (Console.ReadLine() == "y")
                            {
                                animalFound = true;
                            }
                        }
                    }
                    while (animalFound == false);
                }
                if (menuOption == 4)
                {
                    do
                    {
                        x = InputCoordinate('x');
                        y = InputCoordinate('y');
                        if (Landscape[x, y].Warren != null)
                        {
                            animalFound = true;
                            Landscape[x, y].Warren.Inspect();
                            Console.Write("View individual rabbits (y/n)?");
                            viewRabbits = Console.ReadLine();
                            if (viewRabbits == "y")
                            {
                                Landscape[x, y].Warren.ListRabbits();
                            }
                        }
                        else
                        {
                            animalFound = false;
                            //Tells the user there is no warren here.
                            Console.WriteLine("No Warren found at (" + x + ", " + y + ")");

                            //Just in case they didn't mean to inspect:
                            Console.WriteLine("Would you like to continue the simulation? (y/n)");
                            if (Console.ReadLine() == "y")
                            {
                                animalFound = true;
                            }
                        }
                    }
                    while (animalFound == false);
                }
            }
            while (((WarrenCount > 0) || (FoxCount > 0)) && (menuOption != 5));
            Console.ReadKey();
        }
//Logan Dibnah, St Mary's College

Delphi/Pascal Solution

Answer :

Answer :

      if MenuOption = 3 then
        begin
        Repeat
          x := InputCoordinate('x');  
          y := InputCoordinate('y');  
          if not(Landscape[x][y].Fox = nil) then  
            Landscape[x][y].fox.Inspect()  
          else
          begin
            Writeln;
            Writeln('No Fox was found at this location');
            Writeln;
          end
          until not(Landscape[x][y].Fox = nil)
        end;

//Harry Barron, Faringdon Community College

Java Solution

Answer :

Answer :

if (MenuOption == 3)
            {
                x = InputCoordinate('x');
                y = InputCoordinate('y');
                
                //Validating x Co-ordinate
                while(x<0 || x>LandscapeSize){
                   System.out.println("Please enter in an x coordinate within range:");
                   x = InputCoordinate('x');
                }
                
                //Validating y Co-ordinate
                while(y<0 || y>LandscapeSize){
                   System.out.println("Please enter in an y coordinate within range:");
                   y = InputCoordinate('y');
                }
                
                //Validating that a fox is the position selected
                while (Landscape[x][y].Fox == null)
                {
                    System.out.println("Please enter in new coordinates:");
                   x = InputCoordinate('x');
                   y = InputCoordinate('y'); 
                }
                
                if(Landscape[x][y].Fox != null){
                    Landscape[x][y].Fox.Inspect();
                }
            
            }

Python Solution:

Answer :

Answer :

if MenuOption == 3:
        x = self.__InputCoordinate("x")
        y = self.__InputCoordinate("y")
        while self.__Landscape[x][y].Fox is None:
          print "Fox not found"
          x = self.__InputCoordinate("x")
          y = self.__InputCoordinate("y")
        self.__Landscape[x][y].Fox.Inspect()

VB.NET Solution

Answer :

Answer :

If MenuOption = 3 Then
                Do
                    x = InputCoordinate("x")
                    y = InputCoordinate("y")
                    'Gives repsonse when no fox is found
                    If Not Landscape(x, y).Fox Is Nothing Then
                        Landscape(x, y).Fox.Inspect()
                    Else
                        Console.WriteLine()
                        Console.WriteLine("No fox was found at this location")
                        Console.WriteLine()
                    End If
                Loop Until Not Landscape(x, y).Fox Is Nothing
            End If

Add a new animal (Eagles/Coyotes?) that can hunt foxes.[edit]

C# Solution:

Answer :

Answer :

Delphi/Pascal Solution

Answer :

Answer :

Java Solution

Answer :

Answer :

Python Solution:

Answer :

Answer :

VB.NET Solution

Answer :

Answer :

//Ben Sosteric Riddlesdown
Dim InitialEagleCount As Integer
        Dim Variability As Integer
        Dim FixedInitialLocations As Boolean
        Do
            Console.WriteLine("Predator Prey Simulation Main Menu")
            Console.WriteLine()
            Console.WriteLine("1. Run simulation with default settings")
            Console.WriteLine("2. Run simulation with custom settings")
            Console.WriteLine("3. Rabbit Paradise")
            Console.WriteLine("4. Exit")
            Console.WriteLine()
            Console.Write("Select option: ")
            MenuOption = CInt(Console.ReadLine())
            If MenuOption = 1 Or MenuOption = 2 Or MenuOption = 3 Then
                If MenuOption = 1 Then
                    LandscapeSize = 14
                    InitialWarrenCount = 5
                    InitialFoxCount = 5
                    InitialEagleCount = 5
                    Variability = 0
                    FixedInitialLocations = True
                ElseIf MenuOption = 3 Then
                    LandscapeSize = 20
                    InitialWarrenCount = 20
                    InitialFoxCount = 0
                    InitialEagleCount = 0
                    Variability = 1
                    FixedInitialLocations = False

                Else
                    Console.Write("Landscape Size: ")
                    LandscapeSize = CInt(Console.ReadLine())
                    Console.Write("Initial number of warrens: ")
                    InitialWarrenCount = CInt(Console.ReadLine())
                    Console.Write("Initial number of foxes: ")
                    InitialFoxCount = CInt(Console.ReadLine())
                    Console.WriteLine("Initial number of eagles: ")
                    InitialEagleCount = CInt(Console.ReadLine)
                    Console.Write("Randomness variability (percent): ")
                    Variability = CInt(Console.ReadLine())
                    FixedInitialLocations = False
                End If
                Dim Sim As New Simulation(LandscapeSize, InitialWarrenCount, InitialFoxCount, InitialEagleCount, Variability, FixedInitialLocations)
            End If

Class Location
        Public Fox As Fox
        Public Warren As Warren
        Public Eagle As Eagles

        Public Sub New()
            Fox = Nothing
            Warren = Nothing
            Eagle = Nothing
        End Sub
    End Class

Class Simulation
        Private Landscape(,) As Location
        Private TimePeriod As Integer = 0
        Private WarrenCount As Integer = 0
        Private FoxCount As Integer = 0
        Private Eaglecount As Integer = 0
        Private ShowDetail As Boolean = False
        Private LandscapeSize As Integer
        Private Variability As Integer
        Private Shared Rnd As New Random()

        Public Sub New(ByVal LandscapeSize As Integer, ByVal InitialWarrenCount As Integer, ByVal InitialFoxCount As Integer, ByVal InitialEagleCount As Integer, ByVal Variability As Integer, ByVal FixedInitialLocations As Boolean)
            Dim MenuOption As Integer
            Dim x As Integer
            Dim y As Integer
            Dim ViewRabbits As String
            Dim checkfox As Boolean
            Me.LandscapeSize = LandscapeSize
            Me.Variability = Variability
            Landscape = New Location(LandscapeSize, LandscapeSize) {}
            CreateLandscapeAndAnimals(InitialWarrenCount, InitialFoxCount, InitialEagleCount, FixedInitialLocations)
            DrawLandscape()
            Do
                Console.WriteLine()
                Console.WriteLine("0. Advance time by 10 periods hiding detail")
                Console.WriteLine("1. Advance to next time period showing detail")
                Console.WriteLine("2. Advance to next time period hiding detail")
                Console.WriteLine("3. Inspect fox")
                Console.WriteLine("4. Inspect warren")
                Console.WriteLine("5. Inspect Eagle")
                Console.WriteLine("6. Exit")
//Under the same sub
If MenuOption = 5 Then
                    x = InputCoordinate("x")
                    y = InputCoordinate("y")
                    If Not Landscape(x, y).Eagle Is Nothing Then
                        Landscape(x, y).Eagle.Inspect()
                    End If
                End If
            Loop While (WarrenCount > 0 Or FoxCount > 0 Or Eaglecount > 0) And MenuOption <> 6
            Console.ReadKey()

 Private Sub AdvanceTimePeriod(ByVal menuoption As Integer)
            Dim NewFoxCount As Integer = 0
            Dim NewEagleCount As Integer = 0
            If ShowDetail Then
                Console.WriteLine()
            End If
            For z = 0 To 9
                If menuoption <> 0 Then
                    z = 9
                End If
                For x = 0 To LandscapeSize - 1
                    For y = 0 To LandscapeSize - 1
                        If Not Landscape(x, y).Warren Is Nothing Then
                            If ShowDetail Then
                                Console.WriteLine("Warren at (" & x & "," & y & "):")
                                Console.Write("  Period Start: ")
                                Landscape(x, y).Warren.Inspect()
                            End If
                            If FoxCount > 0 Then
                                FoxesEatRabbitsInWarren(x, y)
                            End If
                            If Eaglecount > 0 Then
                                EaglesEatFoxes(x, y)
                            End If
//Under same sub
 For x = 0 To LandscapeSize - 1
                    For y = 0 To LandscapeSize - 1
                        If Not Landscape(x, y).Eagle Is Nothing Then
                            If ShowDetail Then
                                Console.WriteLine("Eagle at (" & x & "," & y & "): ")
                            End If
                            Landscape(x, y).Eagle.AdvanceGeneration(ShowDetail)
                            If Landscape(x, y).Eagle.CheckIfDead() Then
                                Landscape(x, y).Eagle = Nothing
                                Eaglecount -= 1
                            Else
                                If Landscape(x, y).Eagle.ReproduceThisPeriod() Then
                                    If ShowDetail Then
                                        Console.WriteLine("  Eagle has reproduced. ")
                                    End If
                                    NewEagleCount += 1
                                End If
                                If ShowDetail Then
                                    Landscape(x, y).Eagle.Inspect()
                                End If
                                Landscape(x, y).Eagle.ResetFoodConsumed()
                            End If
                        End If
                    Next
                Next
                If NewEagleCount > 0 Then
                    If ShowDetail Then
                        Console.WriteLine("New Eagles born: ")
                    End If
                    For f = 0 To NewEagleCount - 1
                        CreateNewEagle()
                    Next
                End If
                If ShowDetail Then
                    Console.ReadKey()
                End If
                DrawLandscape()
                Console.WriteLine()
            Next
        End Sub

Private Sub CreateLandscapeAndAnimals(ByVal InitialWarrenCount As Integer, ByVal InitialFoxCount As Integer, ByVal InitialEagleCount As Integer, ByVal FixedInitialLocations As Boolean)

Landscape(3, 7).Eagle = New Eagles(Variability, 45)
                Landscape(4, 9).Eagle = New Eagles(Variability, 70)
                Landscape(1, 6).Eagle = New Eagles(Variability, 45)
                Landscape(8, 4).Eagle = New Eagles(Variability, 45)
                Landscape(11, 5).Eagle = New Eagles(Variability, 45)
                Eaglecount = 5
            Else
                For w = 0 To InitialWarrenCount - 1
                    CreateNewWarren()
                Next
                For f = 0 To InitialFoxCount - 1
                    CreateNewFox()
                Next
                For e = 0 To InitialEagleCount - 1
                    CreateNewEagle()
                Next
            End If
        End Sub

Private Sub CreateNewEagle()
            Dim x As Integer
            Dim y As Integer
            Do
                x = Rnd.Next(0, LandscapeSize)
                y = Rnd.Next(0, LandscapeSize)
            Loop While Not Landscape(x, y).Eagle Is Nothing
            If ShowDetail Then
                Console.WriteLine("  New Eagle at (" & x & "," & y & ")")
            End If
            Landscape(x, y).Eagle = New Eagles(Variability, 46)
            Eaglecount += 1
        End Sub

  Private Sub EaglesEatfoxes(ByVal WarrenX As Integer, ByVal WarrenY As Integer)
            Dim FoodConsumed As Integer
            Dim PercentToEat As Integer
            Dim Dist As Double
            Dim RabbitsToEat As Integer
            Dim RabbitCountAtStartOfPeriod As Integer = Landscape(WarrenX, WarrenY).Warren.GetRabbitCount()
            For EagleX = 0 To LandscapeSize - 1
                For EagleY = 0 To LandscapeSize - 1
                    If Not Landscape(EagleX, EagleY).Eagle Is Nothing Then
                        Dist = DistanceBetween(EagleX, EagleY, WarrenX, WarrenY)
                        If Dist <= 3.5 Then
                            PercentToEat = 20
                        ElseIf Dist <= 7 Then
                            PercentToEat = 10
                        Else
                            PercentToEat = 0
                        End If
                        RabbitsToEat = CInt(Math.Round(CDbl(PercentToEat * RabbitCountAtStartOfPeriod / 100)))
                        FoodConsumed = Landscape(WarrenX, WarrenY).Warren.EatRabbits(RabbitsToEat)
                        Landscape(EagleX, EagleY).Eagle.GiveFood(FoodConsumed)
                        If ShowDetail Then
                            Console.WriteLine("  " & FoodConsumed & " foxes eaten by Eagle at (" & EagleX & "," & EagleY & ").")
                        End If
                    End If
                Next
            Next
        End Sub

 Private Sub DrawLandscape()
If Not Landscape(x, y).Eagle Is Nothing Then
                        Console.Write("E")
                    Else
                        Console.Write(" ")
                    End If
                    Console.Write("|")
                Next
                Console.WriteLine()
            Next
        End Sub

Class Eagles
        Inherits Animal
        Enum Genders
            Male
            Female
        End Enum
        Private ReproductionRate As Double
        Private FoodUnitsNeeded As Integer = 10
        Private FoodUnitsConsumedThisPeriod As Integer = 0
        Private Const DefaultLifespan As Integer = 7
        Private Const DefaultProbabilityDeathOtherCauses As Double = 0.1
        Private Const GenderratioEagle As Integer = 34
        Private Gender As Genders

        Public Sub New(ByVal Variability As Integer, ByVal parentsreproductionrate As Double)
            MyBase.New(DefaultLifespan, DefaultProbabilityDeathOtherCauses, Variability)
            FoodUnitsNeeded = CInt(10 * MyBase.CalculateRandomValue(100, Variability) / 100)
            ReproductionRate = parentsreproductionrate * MyBase.CalculateRandomValue(100, Variability) / 100
            If Rnd.Next(0, 100) < GenderratioEagle Then
                Gender = Genders.Male
            Else
                Gender = Genders.Female
            End If
        End Sub

        Public Sub AdvanceGeneration(ByVal ShowDetail As Boolean)
            If FoodUnitsConsumedThisPeriod = 0 Then
                IsAlive = False
                If ShowDetail Then
                    Console.WriteLine("  Eagle dies as has eaten no food this period.")
                End If
            Else
                If CheckIfKilledByOtherFactor() Then
                    IsAlive = False
                    If ShowDetail Then
                        Console.WriteLine("  Eagle killed by other factor.")
                    End If
                Else
                    If FoodUnitsConsumedThisPeriod < FoodUnitsNeeded Then
                        CalculateNewAge()
                        If ShowDetail Then
                            Console.WriteLine("  Eagle ages further due to lack of food.")
                        End If
                    End If
                    CalculateNewAge()
                    If Not IsAlive Then
                        If ShowDetail Then
                            Console.WriteLine("  Eagle has died of old age.")
                        End If
                    End If
                End If
            End If
        End Sub

        Public Sub ResetFoodConsumed()
            FoodUnitsConsumedThisPeriod = 0
        End Sub

        Public Function ReproduceThisPeriod() As Boolean
            Const ReproductionProbability As Double = 0.10
            If Rnd.Next(0, 100) < ReproductionProbability * 100 And Gender = Genders.Female Then
                Return True
            Else
                Return False
            End If
        End Function

        Public Sub GiveFood(ByVal FoodUnits As Integer)
            FoodUnitsConsumedThisPeriod = FoodUnitsConsumedThisPeriod + FoodUnits
        End Sub

        Public Overrides Sub Inspect()
            MyBase.Inspect()
            Console.Write("Food needed " & FoodUnitsNeeded & " ")
            Console.Write("Food eaten " & FoodUnitsConsumedThisPeriod & " ")
            Console.WriteLine()
            MyBase.Inspect()
            Console.Write("Rep rate " & Math.Round(ReproductionRate, 1) & " ")
            If Gender = Genders.Female Then
                Console.WriteLine("Gender Female")
            Else
                Console.WriteLine("Gender Male")
            End If
        End Sub
    End Class

Foxes have a random chance to move towards the closest warren each time period[edit]

C# Solution:

Answer :

Answer :

Delphi/Pascal Solution

Answer :

Answer :

Java Solution

Answer :

Answer :

Python Solution:

Answer :

Answer :

VB.NET Solution

Answer :

Answer :

A fox moves in a random direction if they haven't eaten enough food that turn. (Could be extended to move towards nearest warren as in previous question)[edit]

C# Solution:

Answer :

Answer :

Delphi/Pascal Solution

Answer :

Answer :

Java Solution

Answer :

Answer :

Python Solution:

Answer :

Answer :

VB.NET Solution

Answer :

Answer :

If a fox moves, its food needed for the next time period should increase relative to how far it has traveled[edit]

C# Solution:

Answer :

Answer :

Delphi/Pascal Solution

Answer :

Answer :

Java Solution

Answer :

Answer :

Python Solution:

Answer :

Answer :

VB.NET Solution

Answer :

Answer :

Animals need water as well as food in order to survive[edit]

C# Solution:

Answer :

Answer :

Delphi/Pascal Solution

Answer :

Answer :

Java Solution

Answer :

Answer :

Python Solution:

Answer :

Answer :

VB.NET Solution

Answer :

Answer :

If a fox eats more food than it needs its reproduction rate/coefficient increases(Could be extended to cause a lower chance of movement/range of movement).[edit]

C# Solution:

Answer :

Answer :

Delphi/Pascal Solution

Answer :

Answer :

Java Solution

Answer :

Answer :

Python Solution:

Answer :

Answer :

VB.NET Solution

Answer :

Answer :

Add geographical areas of the grid where only certain animals can survive (i.e. Mountainous regions where rabbits cannot create warrens and where it is harder for foxes to survive, but eagles can flourish, etc.)[edit]

C# Solution:

Answer :

Answer :

Delphi/Pascal Solution

Answer :

Answer :

Java Solution

Answer :

Answer :

Python Solution:

Answer :

Answer :

VB.NET Solution

Answer :

Answer :

If already added another animal(e.g. Eagle), make it so that they prefer hunting around the added geographical areas (Extension of previous code)[edit]

C# Solution:

Answer :

Answer :

Delphi/Pascal Solution

Answer :

Answer :

Java Solution

Answer :

Answer :

Python Solution:

Answer :

Answer :

VB.NET Solution

Answer :

Answer :

For foxes and any other added animals, make it a requirement that there must be 2 or more of the species in adjacent cells to reproduce[edit]

C# Solution:

Answer :

Answer :

Delphi/Pascal Solution

Answer :

Answer :

Java Solution

Answer :

Answer :

Python Solution:

Answer :

Answer :

VB.NET Solution

Answer :

Answer :

(Extension) Make it so that all animals are able to create their own respective homes, e.g. Dens for foxes or nests for eagles[edit]

C# Solution:

Answer :

Answer :

Delphi/Pascal Solution

Answer :

Answer :

Java Solution

Answer :

Answer :

Python Solution:

Answer :

Answer :

VB.NET Solution

Answer :

Answer :