Java
TOPIC 09 – INTRODUCING OBJECTS

AP EXTRA

 

AP LESSON WORK

 

 

QUESTION 1

Consider the following Weapon class that could be used in an RPG game:

 

public class Weapon

{

    public String name;

    public int damage;

    public String enchantmentName;

    public int enchantmentDamage;

}

 

PART 1 – FOLLOW THE ACTIONS

 

Create and manipulate Weapon objects as stated in the actions below.  After each action, be sure to output the weapon's full name (name and enchantmentName together) and the weapon's full damage (damage and enchantmentDamage).

 

ACTIONS

 

1 – Your character opens a chest and finds a weapon.  It's a sword and it does 8 damage.  It is not enchanted.

 

2 – You come across a friend that sharpens your sword improving its damage by  2.

 

3 – You dip your sword into the volcano of Mount Doom.  It is instantly enchanted in "Sword of Fire".  Being enchanted, the weapon does an extra 6 enchanted damage.

 

4 – During a battle with a frost dragon, your sword takes a direct hit and its enchantment is replaced by a cold enchantment.  The enchantment damage is only 4 now.

 

5 – During a battle with dental hygienist spell caster, your sword is transformed into a toothpick that does 1 damage.  The good news is that the enchantment of cold still applies.


PART 2 – CREATE OUR OWN ACTIONS AND CODE

 

Create your own sequence of 5 actions (like above) and create the corresponding code.