Answered step by step
Verified Expert Solution
Link Copied!

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 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

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

Database And Expert Systems Applications 15th International Conference Dexa 2004 Zaragoza Spain August 30 September 3 2004 Proceedings Lncs 3180

Authors: Fernando Galindo ,Makoto Takizawa ,Roland Traunmuller

2004th Edition

3540229361, 978-3540229360

More Books

Students also viewed these Databases questions