Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Consider a scenario where there is a villain in The Revengers game called Maneater. The Maneater has 3 functions: maneaterAttacks, getAttackPower and retreat. Add a
Consider a scenario where there is a villain in The Revengers game called Maneater. The Maneater has functions: maneaterAttacks, getAttackPower and retreat. Add a decorator to the Maneater class that overrides the functions of the parent class by adding to the existing functions.
The solution for this can be implemented using the following steps:
Create a Maneater interface which declares the functions: maneaterAttacks, getAttackPower and retreat
Create a SimpleManeater class which defines the Maneater's functions
Create a decorator class called ManeaterWithSword which also defines the functions of the Maneater interface
Write the client code which will display the output statements mentioned in the output below
The decorated class will define the attack of the Maneater with a sword such that the output looks like this:
A simple looking Maneater approaches.
The Maneater is trying to catch a hold of you! displayed when maneaterAttacks is called
The Maneater yells looking at The Magician and runs away! displayed when retreat function is called
Simple Maneater power: displayed when getAttackedPower is called
A Maneater with huge sword surprises you.
The Maneater is trying to catch a hold of you! displayed when maneaterAttacks is called
The Maneater attacks you with a sword! displayed when retreat function is called
The Maneater yells looking at The Magician and runs away! displayed when getAttackedPower is called
Simple Maneater power:
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started