Question: Help me with this ;( it is due tomrrow and i am stuck :'(!! you will implement the following decorator hierarchy: The requirements for each

Help me with this ;( it is due tomrrow and i am stuck :'(!!

you will implement the following decorator hierarchy:

Help me with this ;( it is due tomrrow and i am

The requirements for each class:

IceCream is an interface:

o It must define a public method eat, which returns an IceCream object.

IceCreamDecorator is an abstract class: o It must implement IceCream. o As in class, it must be set up to decorate other IceCream objects. o 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: o Each decorate needs to add its flavor to the toString (example: adding Chocolate + the toString of the internal toString()). o 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: o The eat method should say the icecream is gone and return null o 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 o Takes an Array or ArrayList of flavors, as Strings o Removes the unsupported flavors o Makes a new BaseIceCream o 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 o 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 o 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 o 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 o 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

Base IceCream > Ice Cream Chocolate Flavor Abstract Ice CreamDecorator Other Flavor Other Flavor2 Other Flavor

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!