Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Plase help me!! you will implement the following decorator hierarchy: The requirements for each class: IceCream is an interface: o It must define a public

Plase help me!!

you will implement the following decorator hierarchy:

image text in transcribed

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

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

Relational Database And Transact SQL

Authors: Lucy Scott

1st Edition

1974679985, 978-1974679980

More Books

Students also viewed these Databases questions

Question

Explain all drawbacks of application procedure.

Answered: 1 week ago

Question

Explain the testing process of accounting 2?

Answered: 1 week ago