INCOMPLETE NEEDS TO BE FORMATTED LESSON WORK QUESTION 1 Create
a class called Weapon with the following specs: DATA
FIELDS (private) ·
String
baseName – basic name of weapon (ie: Sword) ·
String
fullName – basic name with possible enchantment (ie: Sword of fire) ·
int
lowDamage – number specifying the low end of damage
range ·
int
highDamage – number specifying the high end of
damage range ·
int
attackBonus – a bonus applied to weapon holder’s
attack ·
int
defenseBonus – a bonus applied to weapon holder’s
defense ·
int
accuracyBonus – a bonus applied to weapon holder’s
accuracy ·
int
speedBonus – a bonus applied to weapon holder’s
speed ·
int
condition – the health of the weapon, 0 to 100 ·
int
breakability – number from 0 to 5 suggesting how easy it is to damage weapon CONSTRUCTOR ·
public
Weapon(String type) if type is “Hands” baseName
= “Hands” lowDamage
= 1 highDamage
= 3 attackBonus
= 0 defenseBonus
= 0 accuracyBonus
= 0 speedBonus
= 0 condition = 100 breakability = 0 if type is “Sword” baseName
= “Sword” lowDamage
= 4 highDamage
= 8 attackBonus
= 0 defenseBonus
= 0 accuracyBonus
= 1 speedBonus
= 1 condition = 100 breakability = 5 if type is “Axe” baseName
= “Axe” lowDamage
= 6 highDamage
= 12 attackBonus
= 2 defenseBonus
= 0 accuracyBonus
= -1 speedBonus
= -1 condition = 100 breakability = 1 if type is “Staff” baseName
= “Staff” lowDamage
= 3 highDamage
= 5 attackBonus
= 0 defenseBonus
= 4 accuracyBonus
= 0 speedBonus
= 0 condition = 100 breakability = 2 METHODS ·
getMethods
for all data fields ·
public int generateBaseDamage() Used
each time the weapon holder attacks. If
weapon’s condition is 75 or above, then this method return a random number between lowDamage
and highDamage If
weapon’s condition is between 50 and 74, then this method returns a random number between lowDamage
and (lowDamage + highDamage)
/2 If
weapon’s condition is 0, then this method returns 0. ·
public void enchant(String
type) If
type is “fire” then
fullName becomes basename
+ “ of fire” then
both lowDamage and highDamage
go up by 2 then
attackBonus goes up by 1 then
fullName becomes basename
+ “ of lightning” If
type is “ice” then
fullName becomes basename
+ “ of ice” If
type is “speed” then
fullName becomes basename
+ “ of speed” If
type is “unbreakable” then
fullName becomes basename
+ “ of unbreakability” then
condition is set to 100 If
type is “accuracy” then
fullName becomes basename
+ “ of accuracy” if
type is “god” then
fullName becomes basename
+ “ of god” then
attackBonus, defenseBonus,
accuracyBonus and speedBonus
go up by 2 then
breakability is set to zero ·
public void repair() This
method is called whenever the user tries to repair a weapon. A
10% chance that the item is destroyed and its condition is set to 0. A
20% chance that the item’s condition goes up by an amount from 1 to 20. A
20% chance that the item’s condition goes down by an amount from 1 to 20. ·
public void possibleDamage() This method is called when
the weapon is used. A
5% chance that the weapon will be damaged.
Its condition is reduced by the same
amount as breakability. If condition
reaches zero, the setBroken() method is
called. ·
private void setBroken() This
method is called when condition is reduced to zero. It renames the weapon by adding “Broken “ to the front of the
name. ·
public String toString() Returns
a String representation of the object – essentially a large String containing the values of all the data
fields. QUESTION 2 Create
a class called Warrior with the following specs: DATA
FIELDS (private) ·
String
name ·
String
sexe ·
String
class ·
int
experience ·
int
level ·
int
baseAttack ·
int
attack ·
int
baseDefense ·
int
defense ·
int
baseAccuracy ·
int
accuracy ·
int
baseSpeed ·
int
speed ·
int
hpMax ·
int
hp ·
Weapon
weapon CONSTRUCTOR ·
public Warrior (String n, String s,
int at, int de, int ac, int sp, int hp) Data fields are initialized
with the following: Name = n Sexe
= s Class = “Warrior” - will be upgraded at set level-ups Experience = 0 Level = 1 baseAttack
and attack get at baseDefense
and defense get de baseAccuracy
and accuracy get ac baseSpeed
and speed get sp hpMax
and hp get hp weapon is set to a “hands”
weapon METHODS ·
get methods for all data fields ·
public void addExperience(int amount) The experience data field
is increased by amount. If it exceeds
one of the following
level marks, then the levelUp method is called: 500 Uprade to level 2 2000 Upgrade
to level 4 4000 Upgrade to level 5 8000 Upgrade to level 6 and so on… ·
public void levelUp() Increases level by
one. Two points are given to attack,
defense, accuracy or speed. However, the odds are not the same for
every category. Here are the odds: Attack: 4 Defense: 2 Accuracy: 2 Speed: 2 So there is a 40% chance
that a point is given to attack. Both
points might be given
to the same category. ·
public void reduceHP(int
amount) The
hp data field is reduced by amount. If
hp is now less than zero, it is reset to zero. ·
public boolean
isDead() Returns
true if hp is less than or equal to zero.
Otherwise, returns false. ·
public void heal100() If Warrior is still alive
(if hp greater than zero), then hp is set to hpMax. ·
public void heal(int
amount) Increases hp by
amount. However, hp should never
exceed hpmax.
Also, this entire
method only works if Warrior is still alive (hp greater than zero). ·
public void equipWeapon(Weapon newWeapon) Calls
the remove weapon method to remove the currently equipped weapon. ·
private void removeWeapon() This method should only be
called from equipWeapon as it leaves the Warrior object with no weapon
(which is not allowed). That’s why is
private. Removes all the bonus
values from the attack, defense, accuracy and speed data fields. |
|