Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

in java, You will be implementing the Factory Design Pattern to create a Toy Store. Your Toy Store will aid you in ordering different types

in java,

You will be implementing the Factory Design Pattern to create a Toy Store.

Your Toy Store will aid you in ordering different types of puzzles.

Toy Store:

createPuzzle(String type): An abstract method that returns the appropriate Puzzle based on the type

orderPuzzle(String type): Calls createPuzzle to get a puzzle based on the type, then assembles and boxes the puzzle. It returns a String representing the order.

FisherPriceToyStore:

If the user passes in color it will return a PlasticColorPuzzle,

If the user passes in animal it will return a PlasticAnimalPuzzle

Otherwise null

MelissaAndDougToyStore:

If the user passes in color it will return a WoodColorPuzzle,

If the user passes in animal it will return a WoodAnimalPuzzle

Otherwise null

Puzzle Class:

It will hold variables to keep track of the puzzle name, material, and the list of pieces

assemble -> returns a string:

"putting together a NAME"

"This puzzle is made out of MATERIAL"

"Adding the following pieces"

- Name of piece (For each piece)

boxPuzzle -> returns "putting the NAME in a box"

WoodAnimalPuzzle

name: Animal Puzzle by Melissa and Doug

material: wood

pieces: Horse, Sheep, Dog, Cat, Cow, Chicken

PlasticAnimalPuzzle

name: Animal Puzzle by Fisher Price

material: plastic

pieces: Fox, Elephant, Giraffe, Owl, Monkey

WoodColorPuzzle

name: Animal Puzzle by Melissa and Doug

material: wood

pieces: Red Fish, Yellow Fish, Green Fish, Purple Fish, Pink Fish, Orange Fish, Brown Fish, White Fish Black Fish

PlasticColorPuzzle

name: Animal Puzzle by Fisher Price

material: plastic

pieces: Green Dog, Orange Dog, Red Dog, Blue Dog, Yellow Dog, Brown Dog

ToyStoreDriver.java

package factory;

public class ToyStoreDriver {

public ToyStoreDriver() {

}

public void run() {

ToyStore upperClassToyStore = new MelissaAndDougStore();

ToyStore regularToyStore = new FisherPriceStore();

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

System.out.println(upperClassToyStore.orderPuzzle("animal"));

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

System.out.println(upperClassToyStore.orderPuzzle("color"));

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

System.out.println(regularToyStore.orderPuzzle("animal"));

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

System.out.println(regularToyStore.orderPuzzle("color"));

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

}

public static void main(String[] args) {

ToyStoreDriver driver = new ToyStoreDriver();

driver.run();

}

}

output.txt

---------------------

Putting together a Animal Puzzle by Melissa and Doug This puzzle is a made out of wood Adding the following pieces - Horse - Sheep - Dog - Cat - Cow - Chicken Putting the Animal Puzzle by Melissa and Doug in a box

---------------------

Putting together a Color Puzzle by Melissa and Doug This puzzle is a made out of wood Adding the following pieces - Red Fish - Yellow Fish - Green Fish - Purple Fish - Pink Fish - Orange Fish - Brown Fish - White Fish - Black Fish Putting the Color Puzzle by Melissa and Doug in a box

---------------------

Putting together a Animal Puzzle by Fisher Price This puzzle is a made out of plastic Adding the following pieces - Fox - Elephant - Giraffe - Owl - Monkey Putting the Animal Puzzle by Fisher Price in a box

---------------------

Putting together a Color Puzzle by Melissa and Doug This puzzle is a made out of plastic Adding the following pieces - Green Dog - Orange Dog - Red Dog - Blue Dog - Yellow Dog - Brown Dog Putting the Color Puzzle by Melissa and Doug in a box

---------------------

UML:

image text in transcribed

\begin{tabular}{|l|} \hline \multicolumn{1}{|c|}{ Puzzle } \\ \hline \# name: String \\ \# material: String \\ \# pieces: ArrayList> \\ \hline +assemble():String+boxPuzzle():String \\ \hline \end{tabular} \begin{tabular}{|c|} \hline FisherPriceStore \\ \hline+ createPuzzle(String type): Puzzle \\ \hline \end{tabular} \begin{tabular}{|c|} \hline MelissaAndDogStore \\ \hline + createPuzzle(String type): Puzzle \\ \hline \end{tabular} \begin{tabular}{|c|} \hline PlasticColorPuzzle \\ \hline + PlasticColorPuzzle() \\ \hline \end{tabular} \begin{tabular}{|c|} \hline WoodColorPuzzle \\ \hline+ WoodColorPuzzle() \\ \hline \end{tabular} \begin{tabular}{|c|} \hline PlasticAnimalPuzzle \\ \hline + PlasticAnimalPuzzle() \\ \hline \end{tabular} \begin{tabular}{|c|} \hline WoodAnimalPuzzle \\ \hline+ WoodAnimalPuzzle() \\ \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

Database Marketing The New Profit Frontier

Authors: Ed Burnett

1st Edition

0964535629, 978-0964535626

More Books

Students also viewed these Databases questions

Question

How can outcome evaluations vary by stakeholder?

Answered: 1 week ago