Answered step by step
Verified Expert Solution
Question
1 Approved Answer
public class Main { public static void main(String[] args) throws InterruptedException { Grid grid = new Grid(); Predator predator = new Predator(grid); Prey prey =
public class Main { public static void main(String[] args) throws InterruptedException { Grid grid = new Grid(); Predator predator = new Predator(grid); Prey prey = new Prey(grid); grid.setPredator(predator); grid.setPrey(prey); for(int i = 0; i Task #1 Animal, Predator, and Prey Class For this current version of the simulation, we need an abstract class Animal, which will be extended by two subclasses Predator and Prey. Abstract Class Animal 1. Two integer instance variable x and y to store the currently location of an animal. 2. Constructor that takes two integer arguments x and y. 3. Abstract method move (), look(), and act(). a. That is, cach animal can move in the gird, look to check the environment, and act to perform some action. 4. Getters and setters for instance variables. 5. Other necessary methods or variables can be added based on your design Class Predator 1. Override constructor that takes in a Grid (see next task for more information). 2. Set the starting location of the predator at the bottom-right corner of the grid. 3. Override act() method a. If no prey is found, move randomly. b. If a prey is found, move to catch it. 4. Override look() method a. Look for prey in the directions of up, down, left, and right, for a distance of 1 grid cell i. That is, if a predator is at the location (3, 4), it will look to see if there are any prey in location (2, 4), (4,4), (3, 3), or (3,5). 5. Override move () method DEPARTMENT OF COMPUTER SCIENCE CPSC 101 - Computer Programming II a. Either move randomly or move towards a prey i. Randomly moving 1 grid cell in directions of up, down, left, and right (no diagonal move) 6. Other necessary methods of variables can be added based on your design Class Prey 1. Override constructor that takes in a Grid (see next task for more information). 2. Set the starting location of the prey at the upper-left corner of the grid. 3. Override act() method a. If it is not chased by a predator, move randomly. b. If it is chased by a predator, try to run away. 4. Override look () method a. Look for predator in the directions of up, down, left, and right, for a distance of 1 grid cell. i. That is, if a prey is at location (3, 4), it will look to see if there are any predator in location (2,4),(4,4), (3, 3), or (3,5). 5. Override move () method a. Either move randomly or move away from predator i. Randomly moving 1 grid cell in directions of up, down, left, and right (no diagonal move) 6. Other necessary methods or variables can be added based on your design. Task #1 Animal, Predator, and Prey Class For this current version of the simulation, we need an abstract class Animal, which will be extended by two subclasses Predator and Prey. Abstract Class Animal 1. Two integer instance variable x and y to store the currently location of an animal. 2. Constructor that takes two integer arguments x and y. 3. Abstract method move (), look(), and act(). a. That is, cach animal can move in the gird, look to check the environment, and act to perform some action. 4. Getters and setters for instance variables. 5. Other necessary methods or variables can be added based on your design Class Predator 1. Override constructor that takes in a Grid (see next task for more information). 2. Set the starting location of the predator at the bottom-right corner of the grid. 3. Override act() method a. If no prey is found, move randomly. b. If a prey is found, move to catch it. 4. Override look() method a. Look for prey in the directions of up, down, left, and right, for a distance of 1 grid cell i. That is, if a predator is at the location (3, 4), it will look to see if there are any prey in location (2, 4), (4,4), (3, 3), or (3,5). 5. Override move () method DEPARTMENT OF COMPUTER SCIENCE CPSC 101 - Computer Programming II a. Either move randomly or move towards a prey i. Randomly moving 1 grid cell in directions of up, down, left, and right (no diagonal move) 6. Other necessary methods of variables can be added based on your design Class Prey 1. Override constructor that takes in a Grid (see next task for more information). 2. Set the starting location of the prey at the upper-left corner of the grid. 3. Override act() method a. If it is not chased by a predator, move randomly. b. If it is chased by a predator, try to run away. 4. Override look () method a. Look for predator in the directions of up, down, left, and right, for a distance of 1 grid cell. i. That is, if a prey is at location (3, 4), it will look to see if there are any predator in location (2,4),(4,4), (3, 3), or (3,5). 5. Override move () method a. Either move randomly or move away from predator i. Randomly moving 1 grid cell in directions of up, down, left, and right (no diagonal move) 6. Other necessary methods or variables can be added based on your design
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started