AVA code OVERVI EW This is a review exercise, so the primary goal of the exercise is to get your mind working and in the correct space.In this activity you will create a imaginary grid of locations that goes from −?≤?≤?, −?≤?≤?, with the coordinate (0,0) being "home". 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 timesincluding when they are created. Zwill be the map size and will control the highest number allowed on themap before wraping around. Using Jav

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

AVA code

OVERVI EW

This is a review exercise, so the primary goal of the exercise is to get your mind working and in the correct space.In this activity you will create a imaginary grid of locations that goes from −?≤?≤?, −?≤?≤?, with the coordinate (0,0) being "home". 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 timesincluding when they are created. Zwill be the map size and will control the highest number allowed on themap before wraping around. Using Java, create the following classes and primary program that uses the classes that you developed.

INS T RUCT IONS

Create the following classes.

A N I MA L C LA SS

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)

Check 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()andgetY()

getName()

toString()

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.

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

The 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.

Each direction should have an equal chance of happening, so make sure everything is balanced.

Note that there are no parameters. The animal should self move.

Check 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 SS

Inside your main class do the following

Create an array that can hold 6animals.

Fill 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.

Print 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 ION

Before 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.

Commented Correctly
2 pts
O pts
No Marks
2 pts
Full Marks
Does it compile and run?
2 pts
O pts
No Marks
2 pts
Full Marks
Does it run correctly?
6 pts
5 pts
2 pts
O pts
Major Flaws
No Marks
6 pts
Full Marks
Some Minor Flaws
Transcribed Image Text:Commented Correctly 2 pts O pts No Marks 2 pts Full Marks Does it compile and run? 2 pts O pts No Marks 2 pts Full Marks Does it run correctly? 6 pts 5 pts 2 pts O pts Major Flaws No Marks 6 pts Full Marks Some Minor Flaws
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 4 steps with 1 images

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