Question: 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:

in java, You will be implementing the Factory Design Pattern to create

\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

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!