Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Java program Create the following classes ANIMAL CLASS Create an Animal class. Each animal has a name, an x and y integer coordinate and a

Java program image text in transcribed
image text in transcribed
Create the following classes ANIMAL CLASS Create an Animal class. Each animal has a name, an x and y integer coordinate and a max speed which needs to be between 2 and 5. The Animal class should have at minimum the following methods below: .A default constructor that starts the animal at 0,0 with a name of "unknown" and a max speed of 2 A parameter constructor that allows the programmer to input all 4 pieces of information. Check for the constraints. If the input value is invalid, adjust it any way you deem necessary o getx gety . toString() This should print out the name and coordinates of the animal. o touching(Animal x) o This method should determine if the animal is on the same spot as the other animal (x). It should return a Boolean value of true if they are touching, and false if they are not on the same location. . move() o This should move the animal in a single random diretion (up, down, left, right) a random x number of units, where x is between 1 and the max speed (inclusive). Note that there are no parameters. The animal should self move. Check for the constraints. If the animal has moved outside the arena, adjust it any way you deem necessary to keep it in the grid. o o MAIN CLASS Inside your main class do the following Create an array that can hold 5 animals. Create a fight counter that starts at zero and a round counter. Fill the array with 5 different animals with different starting locations and values. You can decide where they start and the name. Print out the starting locations and names of all 5 animals. Then do the following loop. o o o Move all 5 animals randomly. Check all5 animals to see if any of them are on the same spot. If any of the animals are touching it should print out the word "FIGHT" to the screen and show the names of the two animals that are touching o Print out the current locations and names of all 5 animals. o Print a line"+-+-+-+-++++-4++-between each round of the movement. .Repeat the loop above until there are at least five fights. Print out the total number of fights. . Print out the total number of rounds that it took Finally print out the final location of all the animals

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

Securing SQL Server Protecting Your Database From Attackers

Authors: Denny Cherry

2nd Edition

1597499471, 978-1597499477

More Books

Students also viewed these Databases questions

Question

If so, do you use a computerized program? LO.1

Answered: 1 week ago

Question

What is the preferred personality?

Answered: 1 week ago

Question

What is the relationship between humans?

Answered: 1 week ago