Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Need help with the following Java programming problems that go along with each other. Please add comments to each line if possible. (1) Write a

Need help with the following Java programming problems that go along with each other. Please add comments to each line if possible.

(1) Write a class CuteCreature, such that each CuteCreature object has the following instance variables:

Species - a string indicating the type of creature (such as Bowlbasore, Squaretell, or Peekashoe)

Level a positive integer indicating how powerful the creature is Current hit points a non-negative integer indicating how much damage the creature can take before being incapacitated Maximum hit points - a positive integer indicating the highest possible value of current hit points

Attack rating a non-negative integer indicating how effective this creature is at attacking another creature

Defense rating - an integer indicating how effective this creature is at resisting an attack from another creature. Note that unlike attack rating, defense rating can be negative (if affected by a debuff, for example).

Experience points a non-negative integer indicating the creatures cumulative experience. Creatures use experience points to determine when to level up and become more powerful.

Experience value a non-negative integer indicating how many experience points this creature is worth when defeated by another creature

isSpecial a boolean variable that determines whether this creature is considered special. Internally, special creatures are exactly the same as non-special creatures. However, they have a slightly different appearance and are somehow very highly prized by the players of your game.

(2) Within your CuteCreature class, write the following non-static methods:

(a) A constructor with parameters for species, maximum hit points, attack rating, defense rating, experience value, and special status. A newly created CuteCreature should have a level of 1, current hit points equal to the maximum hit points, and zero experience points.

(b) private void levelUp()

This method makes the CuteCreature level up. Leveling up increases the creatures level by 1, in addition to the following changes:

If the new level is between 2-9 (inclusive): Maximum hit points increase by 7, attack and defense ratings increase by 3

If the new level is 10 or over: Maximum hit points increase by 2, attack and defense ratings increase by 1

For all level ups: Experience value increases by 15

For all level ups: The creature is fully healed (i.e., the current hit points is set to the maximum hit points)

The levelUp method should display some text when called, to indicate that the creature is leveling up. Note that levelUp is declared private because its meant to be called only from this classs gainExp method below.

(c) public void gainExp(int exp)

This method makes the CuteCreature gain the specified number of experience points, leveling up if necessary. Call the previously written levelUp method to handle the process of leveling up. Assume that the exp argument is non-negative, and small enough that at most one level up can occur. CuteCreatures require 200 experience points to advance from level 1 to level 2, and the experience required per level increases by 75 for each level thereafter. To illustrate how this works, heres a table of the experience needed for the first five levels:

Current Level Experience Needed for Next Level Cumulative Experience at Next Level
1 200 200
2 275 475
3 350 825
4 425 1250
5 500 1750

The gainExp method should display some text when called, to indicate that the creature is gaining a certain amount of experience.

(d) public void takeDamage(int dmg)

This method makes the CuteCreature take the specified amount of damage to its current hit points. Negative hit points are not allowed, so this method should ensure that the current hit points cannot go below zero. The takeDamage method should display some text when called, to indicate the amount of damage taken. If the damage is enough to bring the current hit points to zero, display some text to indicate that the CuteCreature has been incapacitated.

(e) public void attack(CuteCreature c)

This method makes the CuteCreature perform one attack against a target CuteCreature. The rules governing attack mechanics are as follows:

The attacking creature has a 65% chance to score a regular hit with the attack, a 15% chance to score a critical hit, and a 20% chance of missing altogether.

On a regular hit, the damage to the target creature is the difference between the attacking creatures attack rating and the target creatures defense rating. A minimum of 1 damage is always dealt on a hit, even if this difference is zero or negative.

On a critical hit (crit), the regular damage is doubled. Minimum damage from a crit is 2.

On a miss, no damage is dealt.

Attack Rating of Attacking Creature Defense Rating of Target Creature Attack Result Damage Dealt to Target Creature
14 11 Hit 3
14 11 Crit 6
14 11 Miss 0
14 -2 Hit 16
14 -2 Crit 32
14 -2 Miss 0
14 19 Hit 1
14 19 Crit 2
14 19 Miss 0

The attack method should display some text when called, to indicate which creature is attacking which and the results of that attack. If the target creature is defeated (i.e, has its current hit points brought down to zero) by the attack, the method should also make the attacking creature gain the appropriate amount of experience. Call the previously written takeDamage and gainExp methods as needed.

(f) A toString method that shows all the instance variables of the CuteCreature. For example, the code

CuteCreature c = new CuteCreature("Eckanz", 40, 5, 3, 70, true);

System.out.println(c);

might result in output that looks something like this:

Level 1 Eckanz

--------------

*** Special! ***

HP: 40/40

ATK: 5

DEF: 3

XP: 0/200

XP Val: 70

(3) Write a client program that instantiates at least two CuteCreatures. Thoroughly test your methods to ensure that your code is the very best, that no code ever was. One good way to test might be to create two CuteCreature objects, then have them attack each other until only one of them is left standing.1 Below is some sample output from such a test.

Level 1 Tore-Chick

------------------

HP: 35/35

ATK: 18

DEF: 3

XP: 0/200

XP Val: 210

Level 1 Slacking

----------------

*** Special! ***

HP: 50/50

ATK: 6

DEF: 8

XP: 0/200

XP Val: 210

Tore-Chick attacks Slacking!

Hit! Slacking took 10 damage!

Slacking attacks Tore-Chick!

Hit! Tore-Chick took 3 damage!

Tore-Chick attacks Slacking!

Miss!

Slacking attacks Tore-Chick!

Hit! Tore-Chick took 3 damage!

Tore-Chick attacks Slacking!

Miss!

Slacking attacks Tore-Chick!

Critical hit! Tore-Chick took 6 damage!

Tore-Chick attacks Slacking!

Miss!

Slacking attacks Tore-Chick!

Critical hit! Tore-Chick took 6 damage!

Tore-Chick attacks Slacking!

Hit! Slacking took 10 damage!

Slacking attacks Tore-Chick!

Critical hit! Tore-Chick took 6 damage!

Tore-Chick attacks Slacking!

Critical hit! Slacking took 20 damage!

Slacking attacks Tore-Chick!

Miss!

Tore-Chick attacks Slacking!

Hit! Slacking took 10 damage!

Slacking fainted!

Tore-Chick defeated Slacking!

Tore-Chick gained 210 experience!

Tore-Chick leveled to 2!

Level 2 Tore-Chick

------------------

HP: 42/42

ATK: 21

DEF: 6

XP: 210/475

XP Val: 225

Level 1 Slacking

----------------

*** Special! ***

HP: 0/50

ATK: 6

DEF: 8

XP: 0/200

XP Val: 210

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

Mastering Big Data Interview 751 Comprehensive Questions And Expert Answers

Authors: Mr Bhanu Pratap Mahato

1st Edition

B0CLNT3NVD, 979-8865047216

More Books

Students also viewed these Databases questions

Question

You have

Answered: 1 week ago