Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

java program OVERVIEW This is a review exercise, so as such you may want to spend some time reviewing past concepts. The primary goal of

java program image text in transcribed

image text in transcribed

OVERVIEW This is a review exercise, so as such you may want to spend some time reviewing past concepts. The primary goal of the exercise is to get your mind working and in the correct space In this activity you will create a grid locations that goes from-10 Sx S 10,-10 ys 10 On this grid you will keep track of various animal objects as they move around the grid. Make sure that all animals stay within that grid at all times. Using Java, create the following classes and primary program that uses the classes that you developed. INSTRUCTIONS 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 S. 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. o Check for the constraints. If the input value is invalid, adjust it any way you deem necessary getx() gety tostring() o This should print out the name and coordinates of the animal. touching (Animal x) 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 o move) This should move the animal in a single random direction (up, down, left, right)a random x number of units, where x is between 1 and the max speed (inclusive). o o Note that there are no parameters. The animal should self move o 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. 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 all 5 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-4-+-+-4-4-4-4-4-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

Secrets Of Analytical Leaders Insights From Information Insiders

Authors: Wayne Eckerson

1st Edition

1935504347, 9781935504344

More Books

Students also viewed these Databases questions