Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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. image text in transcribedCharacters:

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

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

Introductory Relational Database Design For Business With Microsoft Access

Authors: Jonathan Eckstein, Bonnie R. Schultz

1st Edition

1119329418, 978-1119329411

More Books

Students also viewed these Databases questions

Question

Determine miller indices of plane X z 2/3 90% a/3

Answered: 1 week ago