Question: Objective: In this lab, you will create a simple RPG ( Role - Playing Game ) . We have different types of characters in our
Objective:
In this lab, you will create a simple RPG RolePlaying Game We have different types of
characters in our game, each with different abilities and attributes.
Part : Character Class Superclass P
Create an abstract class named Character, which will serve as the superclass for all types of
characters in the game.
This class should have the following properties:
quad : A String representing the character's name.
: An int representing the character's level.
health : An int representing the character's health.
This class should have the following methods:
: an abstract method that will prints a message that the character is attacking
override in the derived class
: an abstract method that will print a message that the character is defending
override in the derived class
Getter and setter methods for each property.
Part : Create Subclasses P
Create two subclasses of
: Warrior and Mage.
The class should have the following additional properties:
quad An int representing the Warrior's strength.
The Mage class should have the following additional properties:
quad An int representing the Mage's magic power.
Each subclass should override the attack and defend method to display a unique
attack or defend style. For example, a Warrior might attack with a sword, while a Mage might
use a spell. They should also have getter and setter methods for each new property.
Part : Implement an Interface P
Create an interface named SpecialAbility. This interface should define a method called
useAbility
Next, implement the SpecialAbility interface in the Warrior and Mage classes. In the
useAbility method, print a message that describes the character's special ability. For
example, a Warrior might have a "Berserker Rage" ability, while a Mage might have a "Time
Warp" ability.
Part : Main Class
In a main method, create instances of your Warrior and Mage classes, set their properties,
and call their methods to demonstrate that everything is working as expected. This should
include the
method.
Deliverables:
Character.java
Warrior.java
Mage.java
SpecialAbility.java
Main.java
Good luck and happy coding!
Note on Lab:
You might be wondering why we did not just have a useAbility method in our Character
class. Reasons are:
Flexibility and Decoupling: Using an interface allows for more flexible and decoupled
design. Classes can implement multiple interfaces, enabling them to have a variety of
behaviors without being tied to a specific class hierarchy. In contrast, a class can only
extend one class, which can lead to a more rigid and tightly coupled design.
Evolution of Design: As the game evolves, you might want to add new types of characters
with different special abilities different interfaces If you use an interface for special
abilities, you can easily add new character types that implement this interface without
modifying the existing class hierarchy or affecting other character types.
Specificity of Role: The SpecialAbility interface specifically defines the role of having a
special ability. It's a clear declaration that any class implementing this interface will provide
a particular functionality. This is more specific and targeted than an abstract method in a
superclass, which might imply that all subclasses have or need this method's
implementation.
Encouraging Modular Design: Using interfaces promotes thinking in terms of modular,
interchangeable components. This approach fosters designing systems where individual
parts can be developed, tested, and debugged independently, then combined to create
complex functionalities.
Using an interface like SpecialAbility in this lab helps in defining clear, flexible, and modular
contracts for what characters in the game can do particularly focusing on their unique abilities,
while also allowing for the evolution and expansion of the game's character system.
Deliverables:
Upload the following files in a zip folder that you have created:
Java class files
Screenshot of the Console with the code executing
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
