Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

SUBMIT: Five separate files, Frog.java, Rabbit.java, Snake.java, Turtle.java, and Wolf.java Using the behaviors listed below, write a set of classes that define the behaviors of

SUBMIT: Five separate files, Frog.java, Rabbit.java, Snake.java, Turtle.java, and Wolf.java

Using the behaviors listed below, write a set of classes that define the behaviors of certain animals so it can run in the simulator. For example, the bird moves randomly 1 step in one of 4 directions. Bird.java is an example below.

Create the classes for Frog.java, Rabbit.java, Snake.java, Turtle.java, and Wolf.java and rewrite the bird and mouse code to fit the following animals.

image text in transcribedimage text in transcribed

Download all the files provided below, probably best to create a separate project folder of each assignment, then run AnimalMain.javaimage text in transcribed which will also need:

Animal.javaimage text in transcribed AnimalFrame.javaimage text in transcribed AnimalInfo.javaimage text in transcribed AnimalModel.javaimage text in transcribed AnimalPanel.javaimage text in transcribed

Bird.java and Mouse.java is already done for examples below:

PLUS:

  1. Specifically, NO System calls in any of these submissions
  2. I've also added a getColor() requirement in my Animal interface
  3. The five animals you submit must meet the moving requirements on page 661
  4. DO NOT use case / break.
  5. Only If/else and boolean statements when needed

AnimalMain.java:

public class AnimalMain {

public static void main(String[] args) {

AnimalFrame frame = new AnimalFrame();

frame.add(25, Bird.class);

frame.add(25, Frog.class);

frame.add(25, Mouse.class);

// frame.add(25, Rabbit.class);

// frame.add(25, Snake.class);

// frame.add(25, Turtle.class);

// frame.add(25, Wolf.class);

frame.start();

}

}

Animal.java:

public interface Animal { public String toString(); public int getMove(AnimalInfo info); public Color getColor();

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

AnimalInfo.java:

public interface AnimalInfo { public int getX(); public int getY(); public String getNeighbor(int direction); public int getHeight(); public int getWidth(); }

Bird.java:

import java.awt.Color;

public class Bird implements Animal {

// Constructor

public Bird() {

super(); // nothing to do here, so calling obvious (redundant)

// always requests a zero parameter constructor

}

// over rides Object, and satisfies interface

public String toString() {

return "B";

}

// required by interface, not using AnimalInfo now

public int getMove(AnimalInfo info) {

double r = Math.random();

if (r

return NORTH;

else if (r

return SOUTH;

else if (r

return EAST;

else

return WEST;

}

// choose a color

public Color getColor() {

return new Color(0,0,255);

}

}

Mouse.java:

import java.awt.Color;

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;

}

}

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 Class tostring Bird B Frog F Mouse MM Rabbit V 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 Snake S Turtle T Wolf W Your classes should be stored in files called Bird.java, Frog.java, 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 Mouse.java, Rabbit.java, Snake.java, Turtle.java, and Wolf.java

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered 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

Students also viewed these Databases questions