Difference between revisions of "Weapon class assignment"

From WLCS
Line 1: Line 1:
=== Objective ===
+
== Objective ==
 
* You will learn to create a basic class that encapsulates several attributes and methods
 
* You will learn to create a basic class that encapsulates several attributes and methods
  
=== Purpose ===
+
== Purpose ==
 
* The purpose of the Weapon class is to encapsulate the necessary attributes and methods that represent a weapon in the game
 
* The purpose of the Weapon class is to encapsulate the necessary attributes and methods that represent a weapon in the game
  
=== Attributes ===
+
== Attributes ==
 
The Weapon class should use instance variables to represent the following attributes.  All attributes should be declared '''private''':
 
The Weapon class should use instance variables to represent the following attributes.  All attributes should be declared '''private''':
  
Line 16: Line 16:
 
* miss verb (String): a verb to describe the action of the weapon when it misses (e.g., "whiffs" or "misses").
 
* miss verb (String): a verb to describe the action of the weapon when it misses (e.g., "whiffs" or "misses").
  
=== Methods ===
+
== Methods ==
 
The Weapon class should have the following methods:
 
The Weapon class should have the following methods:
  
'''Constructors:'''
+
===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(): 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.
 
* Weapon(int modifier, String name, String hit, String miss): this specific constructor should initialize all the attributes to the specified values.
  
'''Accessors/Mutators:'''
+
===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 (i.e. getHitPoints(), setDamageModifier(), getName(), etc.).
 
* 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 (i.e. getHitPoints(), setDamageModifier(), getName(), etc.).

Revision as of 09:46, 27 April 2010

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 (i.e. getHitPoints(), setDamageModifier(), getName(), etc.).