Java OOP GUIDE / WORK WEAPON CLASS Topics
TASK –
PART 1 – PARTIAL WEAPON CLASS Consider
the following partially completed Weapon class that represents a weapon this
is part of a video game. Copy it to
your IDE.
TASK –
PART 2 – COMPLETE THE CLASS Fix each
section that says <complete this>. TASK –
PART 3 – CODE ANALYSIS Answer
the following questions: A)
Is
the class mutable or immutable?
Explain. B)
What
will the following code output to screen?
Try to figure it out before running it. C)
What
will the following code output to screen?
Try to figure it out before running it. w2.enchantWeapon(); w2.enchantWeapon(); D)
What
will the following code output to screen?
Try to figure it out before running it. E)
What
will the following code output to screen?
Try to figure it out before running it. F)
Can
the value of damageBonus ever be negative? G)
Add
an instance method named curseWeapon() that does
the opposite of enchantWeapon(). H)
Add
an instance method named getDescriptiveName() that returns the name of the weapon with a descriptor
if the damageBonus is too low or too high. If it is less or equal to -2, the weapon is
“Cursed”. If it is greater or equal to
2, then the weapon is “of Power”. ·
A
Sword with a damageBonus of 3 is a Sword of
Power. ·
A
Staff with a damageBonus of -1 is a Staff. ·
A
Spear with a damageBonus of -2 is a Cursed Spear. I)
Update
the toString() method so that it uses getDescriptiveName() instead of the regular name. J)
What
will the following code output to screen?
Try to figure it out before running it. K)
What
is the least amount of enchantments needed to convert a cursed weapon into a
powerful weapon? L)
In
the main method of a tester class, create a few weapons. Test out all of the instance methods. |
|
|