Plase help me!! you will implement the following decorator hierarchy: The requir
ID: 3803933 • Letter: P
Question
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 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 IceCream’s 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 doesn’t exist. If the cone does, ‘eat’ the cone and reassign the cone without that scoop to the old cone’s 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 FlavorExplanation / Answer
#include<iostream.h>
class IceCream
{
private: char ca[10];
Public:
void eat(){
for(int i=0;i<5;i++){
cout<<endl<<” enter your eat list(max 5) if you press e then it will quit : “;
cin>>ca[i];
if( ca{i]== e) { break;}
}
}
};
class BaseIceCream : public IceCream
{
};
class IceCreamDecorator : public IceCream
{
private: int num; char ch[10];
public:
Void tostring(){ //return the internal ice cream
Cout<<” enter your choice : “; cin>> num;
If( num== 1)
eat()
If(ea==’0’)
Cout<<endl<<” Enter the index of the ice cream cone you wish to devour “;
else
for(int j=0;j<5;j++)
{
Cout<<endl<< ca[j];
}
else if (num==2)
cout<<endl<<” you have no icecream!”;
else if (num==3)
cout<<endl<<” Enter whatever flavors you like from the supported choices: Mint, Chocolate, Vanilla, and Butterscotch : “<<endl<<” Enter q to stop entering flavors”<<endl;
for( k=0;k<10;k++){
cin>>ch[k]>>” “
if(ch[k]==’q’){ break;}
}
else if (num==4)
else
}
Void eat : eat(){ Icecream::eat() }
Void dispdata(){
cout<<”Welcome to the ice cream shop!”;
cout<<endl<<”----Menu---“<<endl;
cout<<endl<<” (1) Eat an icecream cone”<<endl<<”(2) List the icecream cones”<<endl<<”
(3) Add an icecream cone”<<endl<<”(4) Leave the store”<<endl;
}
};
void main()
{
IceCreamDecorator ob1;
ob1.dispdata();
ob1.tostring();
}
//too much long program, I have given these ideas, you can follow these………….