Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

JAVA Details Create the following classes (and one enum) that meet the indicated specifications. The specifications don't describe all of the methods and techniques you

JAVA

Details

Create the following classes (and one enum) that meet the indicated specifications. The specifications don't describe all of the methods and techniques you need to use.

Position : This class holds integer x and y values for the position of something in the Arena. The x and y positions are publicly visible, not used through specific x and y accessor/mutator methods.

Treasure : This is an enum, not a class. It has the following values (define them in this order): Wood, Statue, Coins, Food, Rags

Entity : This is a super class that holds the position of an object in the Arena.

Crate : This is an entity that holds a treasure and associated accessor.

Dragon : This is an entity that has a color (a string) and associated accessor, such as Red or Gold.

Hero : This is an entity that has a name and a list of treasures captured during play.

(A hero has a name and associated accessor. A hero can attack (a method) another object. A hero has an array of treasures and associated accessor.)

Arena : This is a 2 dimensional grid whose size is dynamically determined when it is created. The grid holds references to entities. If there is no entity at a location in the grid, then it is a null reference. When an entity is added to the grid, a reference to it, in the entity's position is created.

(The x position is the first array index. The y position is the second array index. The getTreasureCount method only counts treasures in crates, not those obtained from defeating a dragon.)

When the driver code is run, it starts by creating an Arena of some size, for example, 10 x 10. After the Arena is created, a bunch of entities are added to it, including the Hero. Following that, the Hero is moved to various locations in the Arena. When the Hero moves, if there is an entity already in that spot, the Hero attacks the entity. If the entity is a Crate, then it is crushed and whatever Treasure is stored in the Crate is picked up and stored by the Hero. If the entity is a golden Dragon, it is defeated and a Treasure of Coins is collected by the Hero. If the entity is any other kind of Dragon, it is defeated, but no treasure is obtained.

A few technical notes about the code...

The arena grid size doesn't change after it is created. However, the unit tests for the arena expect the use of an ArrayList of regular Java arrays.

The list of treasures on the hero is dynamic, you'll want to use an ArrayList for it.

Any time the hero moves, remember to change the array reference in the grid to null.

The hero can move to any location on the grid as a single action.

Remember to take advantage of constructor chaining to pass constructor parameters to the right places.

You'll need to override the toString method from the Object class in various places:

A Position in string format looks like: (x, y)

A Crate in string format looks like: Crate with Rags at (x, y)

A Dragon in string format looks like: The Red dragon breathing fire at (x, y)

A Hero is string format looks like: Pat is standing at (x, y)

This assignment uses Inheritance, Aggregation, and Polymorphism; your responsibility is to determine the most appropriate places to use them.

There are various 'get' methods you'll need to write to return things like the list of treasures held by the hero, or how many dragons are in the arena, etc.

Example Driver Output

The provided driver code produces the following output...

--- Initializing Arena --- Successfully added 'Pat standing at (3, 4)' to the game arena. Successfully added 'The Red dragon breathing fire at (4, 4)' to the game arena. Successfully added 'The Golden dragon breathing fire at (6, 6)' to the game arena. Successfully added 'Crate with Wood at (1, 1)' to the game arena. Successfully added 'Crate with Food at (5, 5)' to the game arena. Successfully added 'Crate with Rags at (2, 6)' to the game arena. Successfully added 'Crate with Statue at (3, 3)' to the game arena. Could not add 'Crate with Coins at (3, 4)' because another entity is already there. Could not add 'Kelly standing at (8, 2)' because there is already a hero in the arena. --- Arena status before moving the hero --- There are 7 entities There are 2 dragons There are 1 wood treasures There are 1 statue treasures There are 1 food treasures There are 0 coins treasures There are 1 rag 'treasures' Pat bravely defeated the Red dragon. Pat moved to (4, 4) Pat crushed the crate into bits and found Food. Pat moved to (5, 5) Pat moved to (3, 4) Pat bravely defeated the Golden dragon and came away with gold coins as a prize. Pat moved to (6, 6) Pat moved to (3, 4) Pat crushed the crate into bits and found Rags. Pat moved to (2, 6) --- Hero report for Pat --- Position: (2, 6) Treasures: Food Coins Rags --- Arena status after moving the hero --- There are 3 entities There are 0 dragons There are 1 wood treasures There are 1 statue treasures There are 0 food treasures There are 0 coins treasures There are 0 rag 'treasures'

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

Database Machine Performance Modeling Methodologies And Evaluation Strategies Lncs 257

Authors: Francesca Cesarini ,Silvio Salza

1st Edition

3540179429, 978-3540179429

More Books

Students also viewed these Databases questions

Question

differentiate the function ( x + 1 ) / ( x ^ 3 + x - 6 )

Answered: 1 week ago

Question

Compare the current team to the ideal team.

Answered: 1 week ago

Question

a. Do team members trust each other?

Answered: 1 week ago

Question

How do members envision the ideal team?

Answered: 1 week ago