Question
For this Java program, I have both #1 and #2 already figured out but I'm having trouble getting codes started for #3-7. This is what
For this Java program, I have both #1 and #2 already figured out but I'm having trouble getting codes started for #3-7. This is what I have for the coding so far:
public class CuteCreature { // declare all the instance variables as private private String species; private int level; private int currentHitPoints; private int maximumHitPoints; private int attackRating; private int defenseRating; private int experiencePoints; private int experienceValue; private boolean isSpecial; // the parameterized constructor public CuteCreature (String species, int maximumHitPoints, int attackRating, int defenseRating, int experienceValue, boolean isSpecial) { this.species = species; this.level = 1; this.maximumHitPoints = maximumHitPoints; this.currentHitPoints = this.maximumHitPoints; this.attackRating = attackRating; this.defenseRating = defenseRating; this.experiencePoints = 0; this.experienceValue = experienceValue; this.isSpecial = isSpecial; } // getter and setter for species public String getSpecies () { return this.species; } public void setSpecies (String species) { this.species = species; } // getter and setter for level public int getLevel () { return level; } public void setLevel (int level) { this.level = level; } // getter and setter of current hit points public int getCurrentHitPoints () { return this.currentHitPoints; } public void setCurrentHitPoints (int currentHitPoints) { this.currentHitPoints = currentHitPoints; } // getter and setter of maximum hit points public int getMaximumHitPoints () { return this.maximumHitPoints; } public void setMaximumHitPoints (int maximumHitPoints) { this.maximumHitPoints = maximumHitPoints; } // getter and setter of attack rating public int getAttackRating () { return this.attackRating; } public void setAttackRating (int attackRating) { this.attackRating = attackRating; } // getter and setter for defenseRating public int getDefenseRating () { return this.defenseRating; } public void setDefenseRating (int defenseRating) { this.defenseRating = defenseRating; } // getter and setter for experiencePoints public int getExperiencePoints () { return this.experiencePoints; } public void setExperiencePoints () { this.experiencePoints = experiencePoints; } // getter and setter for experienceValue public int getExperienceValue () { return this.experienceValue; } public void setExperienceValue (int experienceValue) { this.experienceValue = experienceValue; } // getter and setter for isSpecial public boolean getSpecial () { return this.isSpecial; } public void setSpecial (boolean isSpecial) { this.isSpecial = isSpecial; }
Again, #1 and #2 are already solved. Just need help setting them up for the other problems.
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) Add 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.
3) Add the following:
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.
4) Add the following:
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.
5) Add the following:
public void takeDamge(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.
6) Add the following:
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 Attack 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 takeDmg and gainExp methods as needed.
7) 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
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started