Question: Write a class called DoubleCone ( which represents a cone with two scoops of ice cream ) which extends the class Cone ( which represents

Write a class called DoubleCone (which represents a cone with two scoops of ice cream) which extends the class Cone (which represents a cone with a single scoop of ice cream). You will need to override all public Cone methods in your subclass. You will also need to create a method that adds toppings to the cone, called addTopping.
The toString method will need to be adjusted as follows:
If you have only one flavor, return a string that says you have this flavor 2x, and if you have two different flavors, return a string that says you have two flavors.
A summary of the Cone and DoubleCone class methods is shown in the table below. Try to challenge yourself by reusing as much code as possible.
Method/Constructor signature Cone implementation DoubleCone implementation
Cone(String f, boolean w) Sets the ice cream flavor to f and the waffle boolean to w.-
DoubleCone(String f, boolean w)- Sets both ice cream flavors to f and the waffle boolean to w.
DoubleCone(String f1, String f2, boolean w)- Sets the first ice cream flavor to f1, the second to f2, and the waffle boolean to w.
setFlavor(String f) Sets the ice cream flavor to f. Sets both ice cream flavors to f.
setFlavor(String f1, String f2)- Sets the first ice cream flavor to f1, the second to f2.
addTopping(String t)- Sets the topping to the t string.
toString()
Returns "waffle cone with vanilla" if waffle is true and flavor is vanilla.
Otherwise, returns "cone with vanilla" when waffle is false and flavor is vanilla.
This returns a String representation of the ice cream with the flavor as shown by the four examples below:
1. If you have no topping and waffle is set to true and both flavors are the same
"double waffle cone with vanilla x2"
2. If you have no topping and waffle is set to false, and two different flavors
"double cone with vanilla and chocolate"
3. If you have a topping and waffle is set to false, and both flavors are the same
"double cone with vanilla x2 with mochi"
4. If you have a topping and waffle is set to true, and two different flavors
"double waffle cone with vanilla and chocolate with mochi"
You should test your code by running the main method of the runner class. Please do not edit the Cone class, and do not add a main method to your DoubleCone.java file or your code will not be scored correctly.

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!