Answered step by step
Verified Expert Solution
Link Copied!

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 3 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:
1. Create a Maneater interface which declares the 3 functions: maneaterAttacks, getAttackPower and retreat
2. Create a SimpleManeater class which defines the Maneater's functions
3. Create a decorator class called ManeaterWithSword which also defines the 3 functions of the Maneater interface
4. 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: 50.(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: 70.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Modern Database Management

Authors: Fred R. McFadden, Jeffrey Slater, Mary B. Prescott

5th Edition

0805360549, 978-0805360547

More Books

Students also viewed these Databases questions