Question
-------------Write a set of classes that define the behavior of certain animals. They can be used in a simulation of a world with many animals
-------------Write a set of classes that define the behavior of certain animals. They can be used in a simulation of a world with many animals moving around in it. Different kinds of animals will move in different ways (you are defining those differences).
The following is an example set of animals and their respective behavior: (I JUST NEED THE SNAKE CLASS)
Two animals (Bird and Mouse) are given for starters.
public interface Animal { // Each direction resolves to int // based on layout of keypad, 8 at top, 2 at bottom, etc... public static final int NORTH = 8; public static final int SOUTH = 2; public static final int EAST = 6; public static final int WEST = 4; public static final int HOLD = 0; // methods required by interface public String toString(); public int getMove(); public Color getColor(); }
public class Bird implements Animal { // Constructor public Bird() { super(); // nothing to do here, so calling obvious (redundant) // Iverson CS211, always requests a zero parameter constructor } // over-rides Object, and satisfies interface public String toString() { return "B"; }
// required by interface, not even using AnimalInfo in code below public int getMove() { //AnimalInfo info) { double r = Math.random(); if (r
// millions of options here public Color getColor() { return new Color(0,0,255); } }
public class Mouse implements Animal { private boolean myZig; // determines which way to go for each mouse public Mouse() { myZig = true; }
// required by interface public String toString() { return "M"; }
// toggle boolean, so alternates up and left public int getMove() { //AnimalInfo info) { myZig = !myZig; if (myZig) return NORTH; // up else return WEST; // left } // using basic grey public Color getColor() { return Color.GRAY; } }
*THE SNAKE ONE IS THE MOST IMPORTANT ONE, I do not need the other animal classes
Snake S Moves south 1 step, east 1 step, south 1 step, west 2 steps, south 1 step, east 3 steps, south 1 step, west 4 steps, ... ("slithers left and right in increasing length)
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