Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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). As the simulation runs, animals can die when two or more of them end up in the same location, in which case the simulator randomly selects one animal to survive the collision. See your course web site or www.buildingjavaprograms.com for supporting files to run such a simulation.

The following is an example set of animals and their respective behavior:

image text in transcribedimage text in transcribedimage text in transcribed

Here is inside of animalmain java:

// Stuart Reges // 9/6/00 (original code with "Building Java Programs" textbook // Changed 2019,21 by W.P. Iverson, for CS211 project at Bellevue College //

// AnimalMain provides method main for a simple simulation program.

public class AnimalMain { public static void main(String[] args21) { // start work with two animals Animal[] tester = {new Bird(), new Mouse()}; // once done, all seven animals should work //Animal[] tester = {new Bird(),new Mouse(),new Frog(),new Rabbit(),new Snake(),new Turtle(),new Wolf()}; for (int i=0; i

import java.awt.Color; // Stuart Reges // 12/03/04 // // Changed 2019 by W.P. Iverson, for CS211 project at Bellevue College // // The Animal interface defines the methods necessary for an animal // to participate in the animal scramble simulation. It must return a // character when getChar is called that is used for displaying it on // the screen. The getMove method must return a legal move (one of // the constants NORTH, SOUTH, EAST, WEST, CENTER).

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(); } Here is inside of bird.java:

import java.awt.Color; //Stuart Reges //9/6/00 (original code with "Building Java Programs" textbook //Changed 2019 by W.P. Iverson, for CS211 project at Bellevue College 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); } }

Here is inside of mouse.java:

import java.awt.Color; //Stuart Reges //9/6/00 (original code with "Building Java Programs" textbook //Changed 2019 by W.P. Iverson, for CS211 project at Bellevue College 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; } }

. . Universal JAVA Concept: "interface" means you are writing method with a specific name, in this case the getMovel) method can be called thousands of times to get an animal moving. Your coding here is really brief, trivial, short (in retrospect) but the concepts are monumental. SUBMIT: Five separate files Frog.java Rabbit.java Snake.java Turtle.java, Wolf.java This has been called "Critters" in the past, but now SIGNIFICANTLY (January 2021) changed, so work this Assignment, not the wrong one out there on a million other websites. Start with a download all the files provided below, probably best to create a separate project folder of each assignment (probably always best to do that), then run AnimalMain.java which will also need: Animal.java Bird.java o Mouse.java PLUS you must follow my general requirements from "Getting Started": 3. Specifically, NO System calls in any of these submissions 4. The five animals you submit must meet the moving requirements on page 666 of text Class Bird Frog Mouse Rabbit Snake toString B F M V s getMove Moves randomly 1 step in one of the four directions each time Moves randomly 3 steps in one of the four directions Moves west 1 step, north 1 step (zig-zag to the northwest) Move north 2 steps, east 2 steps, south 2 steps ("hops" to the right) 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) Moves south 5 steps, west 5 steps, north 5 steps, east 5 steps (clockwise box) Has custom behavior that you define Turtle Wolf T W

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

More Books

Students also viewed these Databases questions