Question: In Movable class: import java.util.Random; public interface Movable { Random random = new Random(); Direction getMove(); boolean eat(); } In Critter class: import java.awt.*; enum

 In Movable class: import java.util.Random; public interface Movable { Random random= new Random(); Direction getMove(); boolean eat(); } In Critter class: importjava.awt.*; enum Direction { NORTH, SOUTH, EAST, WEST, CENTER }; enum Attack

In Movable class:

import java.util.Random; public interface Movable {

Random random = new Random(); Direction getMove(); boolean eat(); }

In Critter class:

import java.awt.*;

enum Direction { NORTH, SOUTH, EAST, WEST, CENTER }; enum Attack { POUNCE, ROAR, SCRATCH, FORFEIT };

public abstract class Critter {

protected int level = 0; String displayName = null;

public Critter(String name) { this.displayName = name; }

public int getLevel() { return this.level; } protected void incrementLevel(int num) { level = level + num; }

@Override public final String toString() { return this.displayName; } public void win() { } public void lose() { } public void sleep() { } public void wakeup() { } public void reset() { } public void mate() { } public void mateEnd() { }

public Color getColor() { return Color.BLACK; }

public void buffBehavior(CritterState s){ return; }

public void debuff(CritterState s){ return; }

public Attack getAttack(String opponent){ return Attack.FORFEIT; } private int x; private int y; private int width; private int height; private boolean alive = true; private boolean awake = true; private final String[] neighbors = { " ", " ", " ", " ", " " }; protected final int getHeight() { return height; } protected final String getNeighbor(Direction direction) { return neighbors[direction.ordinal()]; } protected final int getWidth() { return width; } protected final int getX() { return x; } protected final int getY() { return y; } protected final boolean isAlive() { return alive; } protected final boolean isAwake() { return awake; } protected final void setAlive(boolean alive) { this.alive = alive; } protected final void setAwake(boolean awake) { this.awake = awake; } protected final void setHeight(int height) { this.height = height; } protected final void setNeighbor(Direction direction, String value) { neighbors[direction.ordinal()] = value; } protected final void setWidth(int width) { this.width = width; } protected final void setX(int x) { this.x = x; } protected final void setY(int y) { this.y = y; } }

Feline extends Critter implements Movable Instance variables: Each Feline will keep track of the number of times it has moved, the amount of times it has not eaten, and the current direction it is going in. You can make these variables private No-arg constructor: A default no-arg constructor. The Critter should be full. And moveCount should be set such that it will change to a new direction at the next (first) call to getMove (). This means that Feline should not start eating once it is created (look at eat)). The string representation of Feline is "Fe". (Hint: think about which inherited instance variable you need to set.) Override getMoveO: Felines are jumpy and tend to go in random directions, so it will go in a new random direction (excluding CENTER) every 5th move (including the first move) that it makes. NOTE: "new random direction" here means a newly chosen direction, not necessarily a unique/different direction. If Feline went NORTH for 5 moves, it should stl be able to choose NORTH as its next 5 moves. Override eat(): Felines don't need to eat that much, so every 5th time it encounters food, it will eat. Override getAttack): Felines should always POUNCE. - Lion extends Feline Instance variables: Each Lion will keep track of the number of fights it wins until it goes to sleep, which will determine its eating behavior. Losing a fight does not decrease the instance variable. You may need a few private variables to keep track of the Lion's movement. - No-arg constructor: A default no-arg constructor. The string representation of Lion is "Lion" Override getColor(): a Lion is YELLOW. (Hint: what method gives you the color of a Critter) Override getMove): The king of beasts does not fear other critters, and they wait for their chance to engage. A Lion will first go SOUTH 5 times, then WEST 5 times, then NORTH 5 times, then EAST 5 times (i.e. a clockwise square pattern). As mentioned, think about what instance variable to initialize to keep track of its movement. override eat(): Return true if the Lion has won at least one fight since it last ate or slept. Think of the Lion as having a hunger that is triggered by fighting. Initially the Lion is not hungry, but winning a fight makes the Lion hungry. When a Lion is hungry, the next call to the eating method should return true. However, once the Lion has eaten OR slept (when sleep() is called), the future calls of eat) should return false until the next win. (Hint: Think about why sleep() would make a lion full again.) Override sleep() and wakeupO: When a Lion goes to sleep, it will reset the number of fights it won to zero, and reverse its display name to "noiL". When it wakes up, it reverts back to "Lion" Note: Handle the behavior of sleep() and wakeup() separately in their own respective methods. Override win(): When a Lion wins a fight, it becomes hungry. Make sure to keep track of the number of fights it won as it affects its eating behavior Do not override getAttack It should have the same behavior as Feline Elephant extends Critter implements Movable Instance variables: Elephants share an int goalx and int goaly coordinate (do not make them private). An Elephant also has a Random object used to generating random ints when picking new goal coordinates. Hint: Look at the modifier for goalx and goalY. What does that mean about all Elephant objects? No-arg constructor: The string representation of Elephant is "El". The random object must be initialized. The very first goalx and goaly should be (0,0) -Override getColor): Elephants are GRAY Override getove(): Elephants are sensible creatures and know that they are safer if they move in herds. Because of this, Elephants have a precise movement pattern. All elephants move towards the shared goalx and goalY coordinate in the simulation. Each Elephant moves towards their goal in the axis in which they are further from their goal. So if an Elephant is further from its goal in the x-axis, it would move EAST or WEST depending on the location of their goal and their current location. When an Elephant is further from its goal in the y-axis, an Elephant would move NORTH or SOUTH. If the distances are equal, choose to move on either thex- ory-axis (but be consistent with your choice always choose x or always choose y If an Elephant reaches the goalx and goalY, it must change the goalx and goaly variables to a new random location on the board. - You do not consider the "wrap-around" case for either axis. For example, consider the case where the world is 60x50, ElephantAlpha is at (o, o), and the goal is at (59, 5). Then ElephantAlpha will move EAST because goalx is further than goalY, even though it can technically move WEST to get to the goalx-coordinate faster on the x-axis. The same holds true for the y-axis. - Override eat): Out in the wild, Elephants need a lot of food, so they will always eat. Override mateO: When an Elephant mates, increment its level by 2. - Do not override getAttackQ from the Critter class. Turtle extends Critter implements Movable No-arg constructor: The string representation of Turtle is Tu - Override getColor): Turtles are GREEN - Override getMove): Turtles always move WEST Override eat(): Turtles like to play it safe when eating. They only eat when there are no hostile animals next to the Turtle (hostile animals are anything that is not an empty space, food, or Turtle). Override getAttack(): Turtles don't always fight, but sometimes they do. Turtles attack with ROAR 50% of the time and try to FORFEIT the other 50%. Slow and steady wins the race, after all. Feline extends Critter implements Movable Instance variables: Each Feline will keep track of the number of times it has moved, the amount of times it has not eaten, and the current direction it is going in. You can make these variables private No-arg constructor: A default no-arg constructor. The Critter should be full. And moveCount should be set such that it will change to a new direction at the next (first) call to getMove (). This means that Feline should not start eating once it is created (look at eat)). The string representation of Feline is "Fe". (Hint: think about which inherited instance variable you need to set.) Override getMoveO: Felines are jumpy and tend to go in random directions, so it will go in a new random direction (excluding CENTER) every 5th move (including the first move) that it makes. NOTE: "new random direction" here means a newly chosen direction, not necessarily a unique/different direction. If Feline went NORTH for 5 moves, it should stl be able to choose NORTH as its next 5 moves. Override eat(): Felines don't need to eat that much, so every 5th time it encounters food, it will eat. Override getAttack): Felines should always POUNCE. - Lion extends Feline Instance variables: Each Lion will keep track of the number of fights it wins until it goes to sleep, which will determine its eating behavior. Losing a fight does not decrease the instance variable. You may need a few private variables to keep track of the Lion's movement. - No-arg constructor: A default no-arg constructor. The string representation of Lion is "Lion" Override getColor(): a Lion is YELLOW. (Hint: what method gives you the color of a Critter) Override getMove): The king of beasts does not fear other critters, and they wait for their chance to engage. A Lion will first go SOUTH 5 times, then WEST 5 times, then NORTH 5 times, then EAST 5 times (i.e. a clockwise square pattern). As mentioned, think about what instance variable to initialize to keep track of its movement. override eat(): Return true if the Lion has won at least one fight since it last ate or slept. Think of the Lion as having a hunger that is triggered by fighting. Initially the Lion is not hungry, but winning a fight makes the Lion hungry. When a Lion is hungry, the next call to the eating method should return true. However, once the Lion has eaten OR slept (when sleep() is called), the future calls of eat) should return false until the next win. (Hint: Think about why sleep() would make a lion full again.) Override sleep() and wakeupO: When a Lion goes to sleep, it will reset the number of fights it won to zero, and reverse its display name to "noiL". When it wakes up, it reverts back to "Lion" Note: Handle the behavior of sleep() and wakeup() separately in their own respective methods. Override win(): When a Lion wins a fight, it becomes hungry. Make sure to keep track of the number of fights it won as it affects its eating behavior Do not override getAttack It should have the same behavior as Feline Elephant extends Critter implements Movable Instance variables: Elephants share an int goalx and int goaly coordinate (do not make them private). An Elephant also has a Random object used to generating random ints when picking new goal coordinates. Hint: Look at the modifier for goalx and goalY. What does that mean about all Elephant objects? No-arg constructor: The string representation of Elephant is "El". The random object must be initialized. The very first goalx and goaly should be (0,0) -Override getColor): Elephants are GRAY Override getove(): Elephants are sensible creatures and know that they are safer if they move in herds. Because of this, Elephants have a precise movement pattern. All elephants move towards the shared goalx and goalY coordinate in the simulation. Each Elephant moves towards their goal in the axis in which they are further from their goal. So if an Elephant is further from its goal in the x-axis, it would move EAST or WEST depending on the location of their goal and their current location. When an Elephant is further from its goal in the y-axis, an Elephant would move NORTH or SOUTH. If the distances are equal, choose to move on either thex- ory-axis (but be consistent with your choice always choose x or always choose y If an Elephant reaches the goalx and goalY, it must change the goalx and goaly variables to a new random location on the board. - You do not consider the "wrap-around" case for either axis. For example, consider the case where the world is 60x50, ElephantAlpha is at (o, o), and the goal is at (59, 5). Then ElephantAlpha will move EAST because goalx is further than goalY, even though it can technically move WEST to get to the goalx-coordinate faster on the x-axis. The same holds true for the y-axis. - Override eat): Out in the wild, Elephants need a lot of food, so they will always eat. Override mateO: When an Elephant mates, increment its level by 2. - Do not override getAttackQ from the Critter class. Turtle extends Critter implements Movable No-arg constructor: The string representation of Turtle is Tu - Override getColor): Turtles are GREEN - Override getMove): Turtles always move WEST Override eat(): Turtles like to play it safe when eating. They only eat when there are no hostile animals next to the Turtle (hostile animals are anything that is not an empty space, food, or Turtle). Override getAttack(): Turtles don't always fight, but sometimes they do. Turtles attack with ROAR 50% of the time and try to FORFEIT the other 50%. Slow and steady wins the race, after all

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!