Answered step by step
Verified Expert Solution
Question
1 Approved Answer
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 x 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.
MethodConstructor signature Cone implementation DoubleCone implementation
ConeString f boolean w Sets the ice cream flavor to f and the waffle boolean to w
DoubleConeString f boolean w Sets both ice cream flavors to f and the waffle boolean to w
DoubleConeString f String f boolean w Sets the first ice cream flavor to f the second to f and the waffle boolean to w
setFlavorString f Sets the ice cream flavor to f Sets both ice cream flavors to f
setFlavorString f String f Sets the first ice cream flavor to f the second to f
addToppingString 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:
If you have no topping and waffle is set to true and both flavors are the same
"double waffle cone with vanilla x
If you have no topping and waffle is set to false, and two different flavors
"double cone with vanilla and chocolate"
If you have a topping and waffle is set to false, and both flavors are the same
"double cone with vanilla x with mochi"
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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started