Homework 3: CuteCreatures




5/5 - (2 votes)

COMP 2150 – Fall 2017
Homework 3: Inheritance
(25 points)
You use your code from Homework 2 to release your game, Super Happy Fun Cute
Creatures World Traveler
, to widespread acclaim. Unfortunately, within only a few months
of release your player base is getting restless! They are easily bored and are demanding that
you add more depth to the game.
In response, you decide to introduce a new breed of
CuteCreatures into your game world.
These creatures will automatically “evolve” once they reach level 20. (Not every creature can
evolve – some will stay in their original form no matter how high they level.) Evolved
creatures are similar to regular creatures, but they gain the following extras:
When the creature evolves, it gains a one-time bonus of 15 maximum and current hit points and 5 attack damage.
This is on top of the regular gains from leveling.
Each evolved creature becomes “attuned” to a particular element. This is done based on the first letter of the
creature’s species:
o A-G creatures attune to fire
o H-M creatures attune to water
o N-S creatures attune to air
o T-Z creatures attune to earth
Evolved creatures gain the ability to perform a special “elemental attack” in addition to their regular attack. This
elemental attack is guaranteed never to miss, but it will never score a critical hit either. Additionally, there is no
20% variance in the attack damage like there is with the regular attack. The damage done by an elemental attack
depends on the element of the target creature:
o If the target creature is of the same element as the attacking creature, the elemental attack deals zero
o If the target creature’s element resists the attacking creature’s element, the elemental attack deals 0.25x
normal attack damage.
o If the target creature’s element is vulnerable to the attacking creature’s element, the elemental attack deals
4x normal attack damage.
o In all other cases, the elemental attack deals the attacking creature’s normal attack damage. This includes
situations in which an evolved creature performs an elemental attack vs. a creature with no element
(which could be an
EvolvableCuteCreature who hasn’t evolved yet, or just a regular CuteCreature).
Number of People: Individual. Feel free to ask me for help, or visit the Computer Science Learning Center
Due: Wed., Sept. 27 by 5:30 pm
Submission: Zip all your Java source files (you can zip the entire project folder if using an IDE) into a single file and
upload it to the proper folder in the eCourseware dropbox at
Coding Style: Use consistent indentation. Use standard Java naming conventions for
ClassNames, CONSTANT_NAMES. Include a reasonable amount of comments.
Grader: Rong Qi,
[email protected]. Questions about grading? Please contact her first!
The table below summarizes the effects of elemental attacks.

Water Air Earth
Earth Fire Air
Fire Earth Water
Air Water Fire

1. (20 pts) Write a subclass EvolvableCuteCreature that extends CuteCreature with the functionality described
above. Here are a few guidelines for this subclass:
Remember that constructors are not inherited, so you’ll need to provide one for the EvolvableCuteCreature
class. Use super to save yourself some coding if possible!
Include an extra instance variable to indicate which element the creature is attuned to.
Add a new elementalAttack(CuteCreature c) method. If an EvolvableCuteCreature tries to call this
method without having evolved yet, display an appropriate error message.
Override the levelUp() method from CuteCreature to handle the evolution process at level 20. (You should
levelUp() as protected rather than private.)
Override the toString() method to include which element the creature is attuned to.
(5 pts) Write a client program that creates some EvolvableCuteCreature objects and tests your methods. You
should especially focus on testing
elementalAttack, since there are many different possible outcomes with that