Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 3 Next »

🎯 Objective

In this lab, you will create a simple RPG (Role-Playing Game). We have different types of characters in our game, each with different abilities and attributes.

Part 1: Character Class (Superclass)

Create a class named Character which will serve as the superclass for all types of characters in the game.

This class should have the following properties:

  • name: A String representing the character's name.

  • level: An int representing the character's level.

  • health: An int representing the character's health.

This class should have the following methods:

  • attack(): Prints a message that the character is attacking.

  • defend(): Prints a message that the character is defending.

  • Getter and setter methods for each property.

Part 2: Create Subclasses

Create two subclasses of Character: Warrior and Mage.

The Warrior class should have the following additional properties:

  • strength: An int representing the Warrior's strength.

The Mage class should have the following additional properties:

  • magic: An int representing the Mage's magic power.

Each subclass should override the attack() method to display a unique attack 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 3: Implement an Interface

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 4: 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 useAbility() method.

Deliverables:

  1. Character.java

  2. Warrior.java

  3. Mage.java

  4. SpecialAbility.java

  5. Main.java

Good luck and happy coding!

🚚  Deliverables

Upload the following files in a zip folder that you have created:

  1. Java class files

  2. Screenshot of the Console with the code executing

  • No labels