Question: Please write code that follows the UML in java. Characters: King, Queen, Knight, Troll Inherit from Abstract Base Class Character Each have a unique toString,

Please write code that follows the UML in java. Please write code that follows the UML in java. Characters: King, Queen,Characters:

King, Queen, Knight, Troll

Inherit from Abstract Base Class Character

Each have a unique toString, that includes the characters name

Each character has a WeaponBehvaior that is set in their constructor

They can call setWeaponBehavior and change their WeaponBehavior

King:

toString returns: name is a Noble King

Weapon Behavior: Sword

Queen

toString returns: name is a beautiful queen

Weapon Behavior: Knife

Knight

toString returns: name is a valiant knight

Weapon Behavior: Bow

Troll

toString returns: name is a funny troll

Weapon Behavior: Axe

WeaponBehavior

An interface with one method: attack

Each weapon implements the interface, and returns a unique message in their attack method.

WeaponAxe:

Randomly returns one of:

Swing an axe

Twirl with an axe

WeaponBow:

Randomly returns one of:

Draw and loose an arrow

Shoot arrow high in the sky

WeaponKnife:

Randomly returns one of:

Slice with knife

Jab with a knife

Sneak up on opponent with knife

WeaponSword:

Randomly returns one of:

Lunge and strike with sword

Fancy turn and slice with sword

Jam opponents blade with sword

WeaponNone:

Randomly returns one of:

Oh no! I lost my weapon

No one let's me have a weapon

Driver:

package strategy;

public class MedievalDriver {

public static void main(String[] args) { Character king = new King("Thomas"); Character queen = new Queen("Isabella"); Character knight = new Knight("Luke"); Character troll = new Troll("Brownwen");

System.out.println(king); System.out.println(king.attack()); System.out.println("----------------");

System.out.println(queen); System.out.println(queen.attack()); System.out.println("----------------");

System.out.println(knight); System.out.println(knight.attack()); System.out.println("----------------");

System.out.println(troll); System.out.println(troll.attack()); troll.setWeaponBehavior(new WeaponNone()); System.out.println(troll.attack());

} }

Example Output:

Thomas is a Noble King Lunge and strike with sword ---------------- Isabella is a beautiful queen Slice with knife ---------------- Luke is a valiant knight Shoot arrow high in the sky ---------------- Brownwen is a funny troll Twirl with an axe. Oh no! I lost my weapon

\begin{tabular}{|c|} \hline WeaponKnife \\ \hline + attack(): String \\ \hline \end{tabular} \begin{tabular}{|c|} \hline WeaponBow \\ \hline + attack(): String \\ \hline \end{tabular} \begin{tabular}{|c|} \hline WeaponNone \\ \hline + attack(0): String \\ \hline \end{tabular}

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 Databases Questions!