Question
This lab is focused on using Inheritance hierarchies in a Decorator design pattern. There is also a bit more polymorphism. . Finally, it utilizes the
This lab is focused on using Inheritance hierarchies in a Decorator design pattern. There is also a bit more polymorphism. . Finally, it utilizes the Factory pattern to make ice cream
Problem:
For this lab, you will implement the following decorator hierarchy:
Here are the requirements for each class, broken down:
IceCream is an interface
It must define a public method eat, which returns an IceCream object
IceCreamDecorator is an abstract class
It must implement IceCream
As in class, it must be set up to decorate other IceCream objects
It should have a toString method that returns its internal IceCreams toString() and an eat method which returns the results of its internal IceCream
Four flavors must extend from IceCreamDecorator. I used Chocolate, Mint, Vanilla, and Butterscotch
Each decorate needs to add its flavor to the toString (example: adding Chocolate + the toString of the internal toString())
Each eat method needs
Report that that specific flavored ice cream scoop was eaten
Return the internal ice cream, removing the eaten scoop
BaseIceCream is the base class
The eat method should say the icecream is gone and return null
The toString should simply return Icecream
Additionally, you must write an IceCreamFactory class. It must provide the following functionality:
IceCreamFactory needs some way to store a list of supported flavors
IceCreamFactory should have a makeIceCream method which
Takes an Array or ArrayList of flavors, as Strings
Removes the unsupported flavors
Makes a new BaseIceCream
Adds only one of each supported flavor to the icecream cone, using decorators
That is, a Mint Chocolate Icecream is fine, but not a Mint Mint Icecream
Returns the new IceCream object
Finally, add a driver. This driver should have an ArrayList of IceCream, an IceCreamFactory object, and a main menu with the following operations:
Quit (Leave the Store, in my example) exit the application
Add an icecream cone
Ask a user for a series of Strings to use as Flavors. Then, use the IceCreamFactory object to make a new ice cream cone and add it to the list of existing cones.
Eat an icecream cone
Ask the user for an index of an ice cream cone. If that cone does not exist, report the cone doesnt exist. If the cone does, eat the cone and reassign the cone without that scoop to the old cones position. If at this point the entire cone is gone, remove the null cone from the IceCream list
List the icecream cones
List all the icecream cones that currently exist
The Sample Output shows the flow for all menu options:
Sample Output:
Welcome to the ice cream shop!
---Menu---
(1) Eat an icecream cone
(2) List the icecream cones
(3) Add an icecream cone
(4) Leave the store
1
Enter the index of the ice cream cone you wish to devour
0
No such cone exists
---Menu---
(1) Eat an icecream cone
(2) List the icecream cones
(3) Add an icecream cone
(4) Leave the store
2
You have no icecream!
---Menu---
(1) Eat an icecream cone
(2) List the icecream cones
(3) Add an icecream cone
(4) Leave the store
3
Enter whatever flavors you like from the supported choices: Mint, Chocolate, Vanilla, and Butterscotch
Enter q to stop entering flavors
Mint
Mint
Mint
Mint
Chocolate
Rum
q
---Menu---
(1) Eat an icecream cone
(2) List the icecream cones
(3) Add an icecream cone
(4) Leave the store
3
Enter whatever flavors you like from the supported choices: Mint, Chocolate, Vanilla, and Butterscotch
Enter q to stop entering flavors
Chocolate
Vanilla
Banana
q
---Menu---
(1) Eat an icecream cone
(2) List the icecream cones
(3) Add an icecream cone
(4) Leave the store
2
Mint Chocolate Icecream
Vanilla Chocolate Icecream
---Menu---
(1) Eat an icecream cone
(2) List the icecream cones
(3) Add an icecream cone
(4) Leave the store
1
Enter the index of the ice cream cone you wish to devour
0
The mint scoop is eaten!
---Menu---
(1) Eat an icecream cone
(2) List the icecream cones
(3) Add an icecream cone
(4) Leave the store
1
Enter the index of the ice cream cone you wish to devour
0
The chocolate scoop is eaten!
---Menu---
(1) Eat an icecream cone
(2) List the icecream cones
(3) Add an icecream cone
(4) Leave the store
1
Enter the index of the ice cream cone you wish to devour
0
The icecream is all gone!
---Menu---
(1) Eat an icecream cone
(2) List the icecream cones
(3) Add an icecream cone
(4) Leave the store
2
Vanilla Chocolate Icecream
---Menu---
(1) Eat an icecream cone
(2) List the icecream cones
(3) Add an icecream cone
(4) Leave the store
4
You enter a sad, icecream less existence
> IceCreamStep 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