Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Need help. I'm behind and do not fully understand design patterns. Please do not copy other answers The purpose of this project is to use

Need help. I'm behind and do not fully understand design patterns. Please do not copy other answers

The purpose of this project is to use the Memento Design Pattern. You will apply this pattern by simulating an Ice Cream shop.

You are the owner of Mimi's Mini Ice Cream Shop. This Ice Cream shop is considered "mini" because of its limited menu.

Modify the program below that allows a user to order an Ice Cream Cone

This ice cream cone can have up to three scoops of ice cream -- but only one flavor

The available flavors are Chocolate, Vanilla, Strawberry and Mimi's Minty

There is a choice of three cone types: regular, sugar or waffle

There is no limit to the number of toppings.

You may use any toppings that you want.

You have found that even with this small number of choices, it can be difficult for a customer to make up their mind. So each time the user completes a selection, save the state of the Ice Cream Cone object to a file.

However, you can only save one cone for each ice cream flavor.

You will need to allow the customer to change the order back to one of the Ice Cream Cone objects written to the file.

When the customer has made his final selection, display the cost of the cone. Create you own algorithm to calculate the cost

/* This class is used to model the properties and behaviors of an ice cream cone. There are currently restriction on the construction of the cone: only one flavor of ice cream is allowed. */ import java.util.*; public class AdvancedIceCreamCone { private int numberOfScoops; private String flavor; private String typeOfCone; private ArrayList toppings = new ArrayList(); //the default constructor creates a one scoop, vanilla ice cream cone using the regular type of cone and no toppings public AdvancedIceCreamCone() { numberOfScoops=1; flavor="vanilla"; typeOfCone="regular"; } /*this constructor lets you create an ice cream code to your liking. It takes in three parameters: the number of scoops, the flavor of the ice cream and the type of cone */ public AdvancedIceCreamCone(int ns,String flv,String cone) { numberOfScoops=ns; flavor=flv; typeOfCone=cone; } //this method returns the number of scoops in the cone public int getNumberOfScoops () { return numberOfScoops; } //this method returns the ice cream flavor public String getFlavor() { return flavor; } //this method returns the type of cone public String getTypeOfCone() { return typeOfCone; } //this method allows you to add one scoop of ice cream at a time public void addScoop() { numberOfScoops=numberOfScoops+1; } //this method allows you to change the ice cream flavor public void setFlavor(String flv) { flavor=flv; } //this method allows you to change the type of cone public void setTypeOfCone(String cone) { typeOfCone=cone; } //this method allows you to add toppings public void addToppings(String top) { toppings.add(top); } //this method returns a String with a list of the toppings public ArrayList getToppings () { return toppings; } //this method overrides the inherited toString() public String toString() { return ("The number of scoops is " + numberOfScoops + ". The flavor is " + flavor + ". And the type of cone is " + typeOfCone + " and the toppings are: " + getToppings()); } } 

Hints

The major difference here will be that the Memento objects themselves are being stored to a file. Do not create/store an ArrayList as shown in the examples.

Since an object is only saved once to a file, make sure you create a new Memento object each time you save a cone.

The logic to read/write a file needs to be put in the Caretaker class.

Close the output file before you open it to read

As always, remember to create a default constructor and override the toString() method for all classes.

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

Databases DeMYSTiFieD

Authors: Andy Oppel

2nd Edition

0071747990, 978-0071747998

More Books

Students also viewed these Databases questions

Question

=+free to pirate employees from competitors?

Answered: 1 week ago