Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

image text in transcribed

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 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

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Design For Mere Mortals

Authors: Michael J Hernandez

4th Edition

978-0136788041

More Books

Students also viewed these Databases questions