Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Below is the code given. Your job is to add a new class that utilizes the Decorator Pattern. Code must continue to be done in
Below is the code given. Your job is to add a new class that utilizes the Decorator Pattern. Code must continue to be done in java, and the Warrior and Builder Classes must remain abstract and untouched. Create a new decorator class named ArmoredWarriorDecorator which has the defense field multiplied by This change should affect all method calculations. You can confirm it is working correctly by running this line of code.
Warrior warrior new ArmoredWarriorDecoratornew AggressiveWarrior.Builderdefensebuild;
public abstract class Warrior
private final int level;
private final int attack;
private final int defense;
protected WarriorBuilder builder
this.level builder.level;
this.attack builder.attack;
this.defense builder.defense;
public int getLevelreturn this.level;
public int getAttackreturn this.attack;
public int getDefensereturn this.defense;
public final double calculatePower
return calculateAttack calculateDefense calculateBoost;
protected int calculateAttack
return this.attack;
protected int calculateDefense
return this.defense;
protected double calculateBoost
return ;
public static abstract class Builder
private final int level;
private int attack;
private int defense;
public Builderint level
this.level level;
public Builder attackint attack
this.attack attack;
return this;
public Builder defenseint defense
this.defense defense;
return this;
public abstract Warrior build;
public class AggressiveWarrior extends Warrior
private AggressiveWarriorBuilder builder
superbuilder;
@Override
protected int calculateAttack
return getLevel getAttack;
@Override
protected int calculateDefense
return getLevel getDefense;
@Override
protected double calculateBoost
return doublegetAttack;
public static class Builder extends Warrior.Builder
public Builderint level
superlevel;
this.attackdefense;
@Override
public AggressiveWarrior build
return new AggressiveWarriorthis;
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