Weapon class assignment

From WLCS
Revision as of 10:24, 30 April 2010 by Admin (talk | contribs)

Objective

  • You will learn to create a basic class that encapsulates several attributes and methods

Purpose

  • The purpose of the Weapon class is to encapsulate the necessary attributes and methods that represent a weapon in the game

Attributes

The Weapon class should use instance variables to represent the following attributes. All attributes should be declared private:

  • damage modifier (integer): an integer added to the damage inflicted when the creature scores a hit.
  • name (String): the name of the weapon (e.g., "sword" or "magic wand").
  • hit verb (String): a verb to describe the action of the weapon when it scores a hit (e.g., "slashes" or "zaps").
  • miss verb (String): a verb to describe the action of the weapon when it misses (e.g., "whiffs" or "misses").

Methods

The Weapon class should have the following methods:

Constructors:

  • Weapon(): the default constructor should initialize the damage modifier to 0, the name to "bare hands", the hit verb to "strikes" and the miss verb to "misses".
  • Weapon(int modifier, String name, String hit, String miss): this specific constructor should initialize all the attributes to the specified values.

Accessors/Mutators:

  • All the attributes are declared private, so you should create accessor and mutator methods for each attribute. The name of the accessor/mutator should follow the standard Java naming conventions
    • getName()
    • setName(String newName)
    • getHitVerb()
    • setHitVerb(String newHitVerb)
    • getMissVerb()
    • setMissVerb(String newMissVerb)
    • getDamageModifier()
    • setDamageModifier(int newDamageModifier)