Need Help with exception

Please Help,

I am trying to create an application that helps the user create an ice cream cone. I managed to get the application to work, however when I inserted code that allows the user to select only three scoops I was no longer able to get my files to compile. I received the following error message when trying to compile: "cannot find symbol: (new IceCreamConeException). Any suggestions on how to fix this would be greatly appreciated:


[code]


public class IceCreamConeException extends Exception
{

public IceCreamConeException(String flavor)
{

super(flavor);

}


}


import javax.swing.*;

public class IceCreamCone
{

protected String[] flavor = {"Chocoloate", "Vanilla", "Strawberry"};
private String options = "";
private int choice;
private int scoops;
protected char initial[] = new char[flavor.length];

public String displayOptions() throws IceCreamConeException
{

for(int x = 0; x < flavor.length; ++x)
{

options = options + "
" +(x + 1) + " for " + flavor[x];
initial[x] = flavor[x].charAt(0);

}


String input = JOptionPane.showInputDialog(null, "which flavor of ice cream would you like?" + options);
for(int y = 0; y < flavor.length; ++y)
if(input.charAt(0) == initial[y])
throw (new IceCreamConeException(flavor[y]));
choice = Integer.parseInt(input);
return(flavor[choice - 1]);

String scps = JOptionPane.showInputDialog(null, " how many scoops would you like? " );

if(scoops > 3)
throw (new IceCreamConeException());


}


}



import javax.swing.*;

public class ThrowIceCreamCone
{

private IceCreamCone conePick;
private String userChoice = new String();

public ThrowIceCreamCone(IceCreamCone icecreamOptions) throws IceCreamConeException
{

conePick = icecreamOptions;
setFlavor();

}


public void setFlavor() throws IceCreamConeException
{

String inputString = new String();
JOptionPane.showMessageDialog(null, "Choose one the the following ice cream flavors: ");
userChoice = conePick.displayOptions();

}


public String getuserChoice()
{

return(userChoice);


}


}




import javax.swing.*;

public class ThrowIceCreamConeII
{

public static void main(String[] args)
{

IceCreamCone conePick = new IceCreamCone();
ThrowIceCreamCone coneFlavor = null;
String userChoice = new String();

try
{

ThrowIceCreamCone selection = new ThrowIceCreamCone(conePick);
coneFlavor = selection;
userChoice = coneFlavor.getuserChoice();

}


catch(IceCreamConeException error)
{

userChoice = error.getMessage();

}

catch(Exception error)
{

userChoice = " You are only allowed a maximum of three scoops ";

}


JOptionPane.showMessageDialog(null, " You selected " + userChoice + " ice cream ");
System.exit(0);

}


}



Comments

  • What this is telling you is there is your constructor requires a parameter.
    eg. throw (new IceCreamConeException(String.valueOf(scoops)));

    BUT, you have a "return" just before this statement.
    You should receive a compile error - statement unreachable.

    Why are you trying to return at this point?



    : cannot find symbol: (new IceCreamConeException)
    :
    : public class IceCreamConeException extends Exception
    : {
    :
    : public IceCreamConeException(String flavor)
    : {
    :
    : super(flavor);
    :
    : }
    : }

    :
    : String scps = JOptionPane.showInputDialog(null, " how many scoops would you like? " );
    :
    : if(scoops > 3)
    : throw (new IceCreamConeException());

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

In this Discussion