Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Please work on DoubleCone.java file!! Two other files are given: runner Doublecone.java : import java.util.Scanner; public class runner_DoubleCone { public static void main(String[] args) {

image text in transcribed

Please work on DoubleCone.java file!!

Two other files are given:

runner Doublecone.java :

import java.util.Scanner;

public class runner_DoubleCone {

public static void main(String[] args) { Scanner scan = new Scanner(System.in); DoubleCone c; System.out.println("Type \"s\" for same flavors, \"d\" for different."); String cons = scan.nextLine().toLowerCase(); System.out.println("Type \"w\" for waffle cone."); boolean w = scan.nextLine().toLowerCase().equals("w"); if (cons.equals("s")) { System.out.println("What flavour?"); String f = scan.nextLine(); c = new DoubleCone(f, w); } else { System.out.println("First flavour?"); String f1 = scan.nextLine(); System.out.println("Second flavour?"); String f2 = scan.nextLine(); c = new DoubleCone(f1, f2, w); } System.out.println(c); System.out.println("Change flavors? (y)"); if(scan.nextLine().toLowerCase().equals("y")) { System.out.println("Type \"s\" for same flavors, \"d\" for different."); String mtd = scan.nextLine().toLowerCase(); if (mtd.equals("s")) { System.out.println("What flavour?"); String f = scan.nextLine(); c.setFlavor(f); } else { System.out.println("First flavour?"); String f1 = scan.nextLine(); System.out.println("Second flavour?"); String f2 = scan.nextLine(); c.setFlavor(f1, f2); } System.out.println(c); } }

}

Cone.java :

public class Cone {

private String flavor; private boolean waffle;

public Cone(String f, boolean w) { waffle = w; flavor = f; }

public void setFlavor(String f) { flavor = f; }

public String toString() { String s = ""; if (waffle) s += "waffle "; s += "cone with " + flavor; return s; }

}

Write a class which extends the class cone (which represents a cone with a single scoop of ice cream). Your class will be named Doublecone, and will represent a cone with two scoops of ice cream. You will need to override all public cone methods in your subclass, plus you will overload both the constructor and the setFlavor methods. A summary of the methods in Cone and the methods you will write in Doublecone is in the table below. You should challenge yourself to rewrite as little code as necessary - try to call existing methods using super and this as much as possible. Method/Constructor signature DoubleCone implementation Cone implementation Sets the ice-cream flavor to f and the waffle boolean to w. Cone(String f, boolean w) DoubleCone (String f, boolean w) Sets both ice-cream flavors to f and the waffle boolean to w DoubleCone (String fi, String f2, boolean w) setFlavor (String f) Sets the ice-cream flavor to f. Sets the first ice-cream flavor to fi, the second to f2, and the waffle boolean to w. Sets both ice-cream flavors to f. Sets the first ice-cream flavor to fl , the second to f2. setFlavor (String fl, String f2) returns a String representation of the ice cream with the flavor as shown by the 2 examples below: returns a String representation of the ice cream with the flavors (in order, first followed by second) as shown by the 2 examples below: toString( cone with vanilla double cone with strawberry and peach waffle cone with chocolate double waffle cone with toffee and toffee 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

Public Finance

Authors: Harvey S. Rosen

3rd Edition

0256083762, 978-0256083767

Students also viewed these Databases questions