Weapon class assignment

From WLCS

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:

  • String name: the name of the weapon (e.g., "sword" or "magic wand").
  • int damageModifier: an integer added to the damage inflicted when the creature scores a hit.
  • String hitVerb: a verb to describe the action of the weapon when it scores a hit (e.g., "slashes" or "zaps").
  • String missVerb: 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(): returns the name attribute
    • setName(String newName): sets the name attribute to the newName parameter
    • getHitVerb(): returns the hit verb
    • setHitVerb(String newHitVerb): sets the hitVerb attribute to the newHitVerb parameter
    • getMissVerb(): returns the miss verb
    • setMissVerb(String newMissVerb): sets the missVerb attribute to the newMissVerb parameter
    • getDamageModifier(): returns the damageModifier
    • setDamageModifier(int newDamageModifier): sets the damageModifier attribute to the newDamageModifier parameter

Other Methods:

  • We are going to add a text description to the name of a weapon to let the user know how powerful it is. For example, if you have a katana and you find a pair of nunchucks, how do you know which is better? Note that for this game, all weapons do the same amount of damage (yes, this is not the most realistic, but much simpler for you to code). Thus, we will be adding a modifier to help the player determine how powerful of a weapon it is. The modifiers are: cursed, normal, shiny, high quality, elite, and magical. This modification need only be made to the getFullName() method in the Weapon class.
  • Add the following method to your Weapon class:
public String getFullName() 
{
	String modifier = "";
	if ( damageModifier < 0 )
		modifier = "cursed";
	else if ( damageModifier < 3 )
		modifier = "normal";
	else if ( damageModifier < 6 )
		modifier = "shiny";
	else if ( damageModifier < 9 )
		modifier = "high quality";
	else if ( damageModifier < 12 )
		modifier = "elite";
	else
		modifier = "magical";
	return modifier + " " + getName();
}

Note: You should still have a getName() method in addition to getFullName()