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---------------------------------------------------
Only do task two please!
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, each 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 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 or 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 #2 Grid Class The class Grid should be a simple implementation of spaces for animals to move within. 1. For this current version, fix the grid size to 10x10. 2. A draw() method that can output the current status of the grid to the terminal. a. Use "B" to represent prey, and "W" to represent predator. b. See sample output for more information. Sample Output The driver class will repeatedly print out the grid at every time unit. Each of them will look similar to the following: | BI 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 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, each 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 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 or 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 #2 Grid Class The class Grid should be a simple implementation of spaces for animals to move within. 1. For this current version, fix the grid size to 10x10. 2. A draw() method that can output the current status of the grid to the terminal. a. Use "B" to represent prey, and "W" to represent predator. b. See sample output for more information. Sample Output The driver class will repeatedly print out the grid at every time unit. Each of them will look similar to the following: | BI 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
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