java please dont take other website'answer. rthis is actually practice question ANIMALCLASS Create an Animal class. Each animal has a name, an x and y integer coordinate. The Animal class should have at minimum the following methodsbelowbut you may want to add more if necessary: Also note, everyanimal will need to have to have “z”passed to it so that it knows how big the map is. •A constructor that starts the animal at 0,0 with a name of "Unknown Animal"and only accepts a single int value (int mapSize). •A parameter constructor that allows the programmerto input all 4pieces of information.(x,y, name, mapSize)oCheck the parameters for valid input based on the constraints. Ifany of the input valuesis invalid, adjust it any way you deem necessary in order to make it valid. •getX()and getY() •getName() •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 a secondanimal(x). It should return a boolean value of true if they are touchingand false if they are not on the same location. move() oWhen this method is run, the animal will move in a random direction. oThe animal can move in one of eight directions. ▪The animal could move left, or right, or up, or down. ▪If the animal moves in one of these directions, it should move random xnumber of units, where xis between 1 and 2(inclusive). ▪The animal could move diagonally. ▪If it moves diagonally, then it will move horizontally 1 and vertically 1. There is no random amount.oEach direction should have an equal chance of happening, so make sure everything is balanced.oNote that there are no parameters. The animal should self move.oCheck for the range constraints. ▪First make sure the animal is still on the grid, if it isn't, then wrap the animal to move it back onto the grid. ▪To wrap it around the grid. An animal that moves to z+1should be relocated to -z+1.If an animal goes to -z-2, then it wraps to z-2. ▪I.E. If z = 30, an animal that moves to 31should be relocated to-29,while an animal that goes to -32, wraps to +28to keep it inside the z=30 box. ▪Check both x and y coordinatesat all times including construction.MA I N C LA SSInside your main class do the following •Create an array that can hold 6animals. oFill the array with 5animals with names and locations of your choice. oFinish filling the array with one default animal. oChoose a mapsize that is more than 15, but is the samefor all the animals. ▪Hint: aconst int mapSize = ?, is a good way to do this. •Create afight counter that starts at zero and a round counter. •Print out the starting locations and names of all theanimals. •Then dothe following loop. oMove alltheanimals randomly. oCheck all the animals to see if any of them are on the same spot. ▪Make sure to check for touching animals AFTERmoving all the animals. oIf any of the animals aretouching it should print out the word “FIGHT”to the screen and show the namesof the two animals that are touching. oPrint out the current locations and names of all animals. oPrint a line "[####################################]"between each round of the movement. •Repeat the loop above until there are at least 12fights. •Print out the total number of fights.•Print out the total number of rounds that it tookto get to ten fights. BEFORE S UB M IS S IONBefore submitting your assignment,make sure your program is correctly Java Documented and is listed as your name as the author. Make sure to check that x and y are inside the map from -z to +z at all times, don’t allow it to start outsidethe map, or move outside the map.

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question
100%

java

please dont take other website'answer. rthis is actually practice question

ANIMALCLASS

Create an Animal class. Each animal has a name, an x and y integer coordinate. The Animal class should have at minimum the following methodsbelowbut you may want to add more if necessary:

Also note, everyanimal will need to have to have “z”passed to it so that it knows how big the map is.

•A constructor that starts the animal at 0,0 with a name of "Unknown Animal"and only accepts a single int value (int mapSize).

•A parameter constructor that allows the programmerto input all 4pieces of information.(x,y, name, mapSize)oCheck the parameters for valid input based on the constraints. Ifany of the input valuesis invalid, adjust it any way you deem necessary in order to make it valid. •getX()and getY()

•getName()

•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 a secondanimal(x). It should return a boolean value of true if they are touchingand false if they are not on the same location.

move()

oWhen this method is run, the animal will move in a random direction.

oThe animal can move in one of eight directions. ▪The animal could move left, or right, or up, or down.

▪If the animal moves in one of these directions, it should move random xnumber of units, where xis between 1 and 2(inclusive).

▪The animal could move diagonally.

▪If it moves diagonally, then it will move horizontally 1 and vertically 1. There is no random amount.oEach direction should have an equal chance of happening, so make sure everything is balanced.oNote that there are no parameters. The animal should self move.oCheck for the range constraints.

▪First make sure the animal is still on the grid, if it isn't, then wrap the animal to move it back onto the grid.

▪To wrap it around the grid. An animal that moves to z+1should be relocated to -z+1.If an animal goes to -z-2, then it wraps to z-2.

▪I.E. If z = 30, an animal that moves to 31should be relocated to-29,while an animal that goes to -32, wraps to +28to keep it inside the z=30 box.

▪Check both x and y coordinatesat all times including construction.MA I N C LA SSInside your main class do the following

•Create an array that can hold 6animals.

oFill the array with 5animals with names and locations of your choice.

oFinish filling the array with one default animal.

oChoose a mapsize that is more than 15, but is the samefor all the animals.

▪Hint: aconst int mapSize = ?, is a good way to do this.

•Create afight counter that starts at zero and a round counter.

•Print out the starting locations and names of all theanimals.

•Then dothe following loop.

oMove alltheanimals randomly.

oCheck all the animals to see if any of them are on the same spot.

▪Make sure to check for touching animals AFTERmoving all the animals.

oIf any of the animals aretouching it should print out the word “FIGHT”to the screen and show the namesof the two animals that are touching.

oPrint out the current locations and names of all animals.

oPrint a line "[####################################]"between each round of the movement.

•Repeat the loop above until there are at least 12fights.

•Print out the total number of fights.•Print out the total number of rounds that it tookto get to ten fights.

BEFORE S UB M IS S IONBefore submitting your assignment,make sure your program is correctly Java Documented and is listed as your name as the author. Make sure to check that x and y are inside the map from -z to +z at all times, don’t allow it to start outsidethe map, or move outside the map.

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps

Blurred answer
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY