Question: Write a complete class from scratch , the IceCreamCone class. You will also write a driver to interact with a user and to test all

Write a complete class from scratch, the IceCreamCone class. You will also write a driver to interact with a user and to test all of the IceCreamCone methods.

Lab:

Cone

Ice Cream

o Flavor

o Topping

Ice Cream Cone

Driver

Part I: Cone

An ice cream cone has two main components, the flavor of ice cream and the type of cone. Write a Cone class that takes an integer in its constructor. Let a 1 represent a sugar cone, let a 2 represent a waffle cone, and let a 3 represent a cup. Make sure to set an invalid entry to a default cone. Write a method to return the price of the cone. The sugar cone is $0.59, the waffle cone is $0.79, and the cup is free. Write a toString() method to return a String indicating the type of cone that was selected. See the example below for how to format the toString() method. Is this class immutable?

Note: If you need a carriage return in a String, use " "

Part II: Ice Cream

Download the following files: PLEASE SEE DROPBOX LINK

Topping.java PLEASE CLICK ON LINK : https://www.dropbox.com/s/jt9jq6sesonji2d/Topping.java?dl=0

o public double price() //toppings are $0.15 ("no topping" is free)

Toppings.java PLEASE CLICK ON LINK : https://www.dropbox.com/s/dhuyh7y402xtgic/Toppings.java?dl=0

//this file has the following public interface:

o public static Toppings getToppings() //singleton design pattern

o public int numToppings() //the number of different toppings

o public String listToppings() //list (and number) available toppings

o public Topping getTopping(int index) //1-based

Flavor.java PLEASE CLICK ON LINK : https://www.dropbox.com/s/1ar1ecq7tsodil7/Flavor.java?dl=0

Flavors.java PLEASE CLICK ON LINK : https://www.dropbox.com/s/9kge30rn94d0qwl/Flavors.java?dl=0

//this file has the following public interface:

o public static Flavors getFlavors() //singleton design pattern

o public int numFlavors() //the number of different flavors

o public String listFlavors() //list (and number) available flavors

o public Flavor getFlavor(int index) //1-based

Ice cream has a number of scoops, a flavor, and a topping. Write an IceCream constructor that accepts the number of scoops (up to 3), a Flavor object and a Topping object. Set default values if the input is invalid (protect against null). Write a method to return the price (each scoop over 1 adds $0.75 to the cost of the ice cream) and a method to return a String listing the ice cream parameters selected.

Part III: Ice Cream Cone

Download the following file: PLEASE CLICK ON LINK : https://www.dropbox.com/s/jzjmll7spmr1n5l/Currency.java?dl=0

Currency.class //this file has the following public interface:

o public static String formatCurrency(double val) //formats the double as a String representing US currency.

The IceCreamCone is composed of the Cone and the IceCream. Write a constructor that accepts an IceCream and a Cone (protect against null), a method to return the price (the base price is $1.99 plus any costs associated with the components), and a method to return a String display of the ice cream cone ordered by the user. Use the Currency class to format the total price of the Ice Cream Cone. Does this class use proper encapsulation techniques?

Note: Without using the Currency class, it is possible to get final prices that are not quite correct, such as 3.5300000000000002. Why does this happen?

Part IV: Ice Cream Driver

Download the following file: PLEASE CLICK ON LINK : https://www.dropbox.com/s/lkkicxi36wmn8m1/Keyboard.java?dl=0

Keyboard.class //this file has the following public interface:

o public static Keyboard getKeyboard() //singleton design pattern

o public int readInt(String prompt)

o public double readDouble(String prompt)

o public String readString(String prompt) Write a driver to obtain the ice cream cone order from the user. Allow multiple ice cream cones to be ordered, and keep a running total of the price of the ice cream cones. Of course, wait (loop) for the user to input valid entries. Thus, you are checking for valid entries in the driver and in the constructor of your objects. This is defensive programming, although it results in some code duplication.

In addition to main, include the following methods in your driver:

1. public static Flavor getFlavorChoice() //look at the methods available in the Flavors class

2. public static Topping getToppingChoice() //look at the methods available in the Toppings class

3. public static int getScoopsChoice()

4. public static Cone getConeChoice()

Example output as a jpg in the LINK. : https://www.dropbox.com/s/wnn776yzaaq1vmz/lab04.jpg?dl=0

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!