Submission 5: Polymorphism and Abstract Classes
Objective: Apply polymorphism and abstract classes to generalize behaviors.
Instructions:
Convert
Enemy
to an Abstract Class:Declare
Enemy
as abstract.Define abstract methods such as
void specialAttack(Player player)
.
Implement Abstract Methods in Subclasses:
Goblin
andDragon
:Implement
specialAttack(Player player)
with behaviors unique to each enemy.
Introduce Polymorphism in Combat:
Use
ArrayList<Enemy>
to store different enemy types.During combat, invoke
specialAttack(Player player)
without knowing the specific enemy type.
Enhance the
Item
Class:Make
Item
an abstract class.Define abstract methods like
void use(Player player)
.
Implement Polymorphic Item Usage:
Allow the player to use items without knowing the specific item subclass.
Deliverables:
Updated source code files.
Screenshot of program running
COSC-1437 / ITSE-2457 Computer Science Dept. - Author: Dr. Kevin Roark