Question: In Java, use the Builder design pattern to create a Warrior classes: AggressiveWarrior and DefensiveWarrior. Warriors have 3 attributes, all integers ( int ) :

In Java, use the Builder design pattern to create a Warrior classes: AggressiveWarrior and DefensiveWarrior.
Warriors have 3 attributes, all integers (int): level, attack, and defense. Level is required, while attack
and defense are optional.
Aggressive warriors have a default attack of 3 and a default defense of 2.
Defensive warriors have a default attack of 2 and a default defense of 3.
Note that during the creation of either Aggressive or Defensive Warriors, the default value can be changed.
Warriors must be immutable.
The order of things matters in your class:
Fields
Constructor
Methods
Builder
Builder fields
Builder Constructor
Builder methods
Builder build() Finally demonstrate in the main method the successful creation of 4 warriors. Where 2 are of level 1 with base stats, and the other 2 demonstrating the ability of overwriting the default stats.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!