Question: You will be implementing the Strategy Design Pattern to create Football Players and have them run plays. Players: QuarterBack, Receiver, and Lineman Inherit from Abstract

You will be implementing the Strategy Design Pattern to create Football Players and have them run plays.

Players:

  • QuarterBack, Receiver, and Lineman
  • Inherit from Abstract Base Class Player
  • Each have a unique toString, that includes the players name
  • Each character has a OffenceBehavior and a DefenceBehavior, which is set in the constructor
  • They can call setOffenceBehavior and change their offenceBehavior
  • They can call setDefenceBehavior and change their defenceBehavior

QuarterBack:

  • setOffenceBehavior will randomly choose between setting the behavior to a RunBehavior and a PassBehavior
  • setDefenceBheavior will set the defenceBehavior to null

Receiver:

  • setOffenceBehavior will set the offenceBehavior to a new ReceiverBehavior
  • setDefenceBehavior will set the defenceBehavior to null

LineMan:

  • setOffenceBehavior will set the offenceBehavior to OBlockBehavior
  • setDefenceBehavior will randomly choose between between Block, Strip, and Sack Behavior

DefenceBehavior

  • An interface with one method: play
  • Each child implements the interface, and returns a unique message in their play method.

BlockBehavior:

  • returns "block a {kick, punt, pass, or catch}", where one of the moves are picked randomly

StripBehavior:

  • returns "Strip a ball from runners hands"

SackBehavior:

  • returns "Sack the quarterback"

OffenceBehavior

  • An interface with one method: play
  • Each child implements the interface, and returns a unique message in their play method.

OBlockBehavior:

  • returns "block defenders"

RunBehavior:

  • returns "runs a {drive (up the gut), draw, pitch, reverse}" -> randomly picking one move

PassBehavior:

  • returns "throws a {slant route, out route, seem route, screen pass, hail mary}" -> randomly picking one move

ReceiveBehavior:

  • returns "runs a {slant route, out route, seem route, screen pass, hail mary}" -> randomly picking one move

UML Diagram

You will be implementing the Strategy Design Pattern to create Football Players

Driver.java

package strategydesignpattern;

public class Football {

public Football() {}

public void play() {

Player[] players = new Player[3];

players[0] = new QuarterBack("Russel Wilson");

players[1] = new Receiver("Tyler Lockett");

players[2] = new Lineman("BJ Finney");

System.out.println("***** Offencive Plays *****");

displayPlays(players);

turnover(players);

System.out.println(" ***** Defencive Plays *****");

displayPlays(players);

}

public void displayPlays(Player[] players) {

for(Player player : players) {

System.out.println(player.name + " " + player.play());

}

}

public void turnover(Player[] players) {

for(Player player : players) {

player.turnover();

}

}

public static void main(String[] args) {

Football football = new Football();

football.play();

}

}

Sample output:

***** Offencive Plays ***** Russel Wilson throws a seem route Tyler Lockett runs a slant route BJ Finney Block Defenders

***** Defencive Plays ***** Russel Wilson not playing Tyler Lockett not playing BJ Finney Strip a ball from runners hands

> DefenceBehavior + play(): String Player # name:String defence: boolea # defenceBehavior: DefenceBehavior # offenceBehavior: OffenceBehavior BlockBehavior SackBehavior StripBehavior + play0: String + play0: String + playo: String + Player(String name) + setDefenceBehavior(): void + setOffenceBehavior(): void + play): String + turnover(): void > OffenceBehavior + playO: String OBlockBehavior RunBehavior PassBehavior Receive Behavior + play0: String + playo: String + play0: String + play0: String Quarterback Receiver Lineman + Quarterback(String name) + setOffenceBehavior(): void + setDefenceBehavior(); void + Receiver(String name) + setOffenceBehavior(): void + setDefenceBehavior(): void + Lineman(String name) + setOffenceBehavior: void + setDefenceBehavior(): void

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!