In: Computer Science
Create an IceCreamConeException class whose constructor recetves a String that consists of an ice creams cone’s flavour and the number of scoops Create an IceCreamCone class with two fields - flavor and scoops The IceCreamCone constructor calls two data entry methods — getFlavor() and getScoops() The getScoops() method throws an IceCreamConeException when the scoop quantity exceeds 3 Write a program that establish three TceCreamCone objects and handles the Exception
//Java program
import java.util.Scanner;
class IceCreamConeException extends Exception
{
public IceCreamConeException(String s)
{
super(s);
}
}
class IceCreamCone{
private String flavor;
private int scoops;
public IceCreamCone() throws IceCreamConeException
{
flavor = getFlavor();
scoops = getScoops();
}
private int getScoops() throws
IceCreamConeException {
Scanner in = new
Scanner(System.in);
System.out.print("Enter number of
Scoops : ");
int scoop = in.nextInt();
if(scoop > 3)throw new
IceCreamConeException("out of limit");
in.close();
return scoop;
}
private String getFlavor() {
Scanner input = new
Scanner(System.in);
System.out.print("Enter Flavor name
: ");
String flavor =
input.nextLine();
input.close();
return flavor;
}
}
public class IceCream {
public static void main(String args[]) {
try {
IceCreamCone
cone1 = new IceCreamCone();
} catch (IceCreamConeException e)
{
e.printStackTrace();
}
try {
IceCreamCone
cone2 = new IceCreamCone();
} catch (IceCreamConeException e)
{
e.printStackTrace();
}
try {
IceCreamCone
cone3 = new IceCreamCone();
} catch (IceCreamConeException e)
{
e.printStackTrace();
}
}
}