Question
Write Following code in java and include javadoc comments in the methods classes and parameters please You will be implementing the Factory Design Pattern to
Write Following code in java and include javadoc comments in the methods classes and parameters please
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
DRIVER:
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:
---------------------
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
---------------------
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started