Results 1 to 4 of 4
Thread: Need Help
- 12-03-2008, 06:36 AM #1
Member
- Join Date
- Sep 2008
- Posts
- 9
- Rep Power
- 0
Need Help
Hello,
I need help with a project I am working on for school, what I need to do is create an application that helps a user select an ice cream cone flavor and how many scoops on the come. I managed to get the IceCreamconeException file to compile, however, I get error messages when I try to compile the IceCreamCone file. In the error refrences an identifier that is expected, I tried to investigate how to correct this but had no luck. Any suggestions would be appreciated, here are the error messages:
C:\Users\Owner\Documents\213191d_Ch15\Chapter.15>j avac IceCreamCone.java
IceCreamCone.java:28: <identifier> expected
inputString = JOptionPane.showInputDialog(null, "What flavor of ice cream wou
ld you like?");
^
IceCreamCone.java:29: <identifier> expected
flavor = inputString;
^
IceCreamCone.java:32: <identifier> expected
inputString = JOptionPane.showInputDialog(null, "How many scoops of ice crea
m woul you like on your cone?");
^
IceCreamCone.java:33: <identifier> expected
scoops = Integer.parseInt(inputString);
^
IceCreamCone.java:36: illegal start of type
try
^
IceCreamCone.java:56: <identifier> expected
JOptionPane.showMessageDialog(null, "You chose" + flavor + "with" + scoops +
"of ice cream");
^
6 errors
Java Code:public class IceCreamConeException extends Exception { int scoops, scps; String flav; public IceCreamConeException(String flavor, int scoops) { flav = flavor; scps = scoops; } } import javax.swing.*; public class IceCreamCone { String flavor,inputString ; int scoops,result; inputString = JOptionPane.showInputDialog(null, "What flavor of ice cream would you like?"); flavor = inputString; inputString = JOptionPane.showInputDialog(null, "How many scoops of ice cream woul you like on your cone?"); scoops = Integer.parseInt(inputString); public IceCreamCone() { setFlavor(); setScoops(); } void setScoops() throws IceCreamConeException { if(scoops > 3) throw (new IceCreamConeException()); JOptionPane.showMessageDialog(null, "You are only allowed a maximum of three scoops"); } try { result = flavor; result = scoops; } catch(IceCreamConeException exception) { JOptionPane.showMessageDialog(null, exception.getMessage()); } JOptionPane.showMessageDialog(null, "You chose" + flavor + "with" + scoops + "of ice cream"); }
- 12-03-2008, 01:38 PM #2
setFlavor method?
I don't see the implementation of the setFlavor() method that's being called from the IceCreamCone constructor.
CJSLChris S.
Difficult? This is Mission Impossible, not Mission Difficult. Difficult should be easy.
- 12-03-2008, 01:42 PM #3
Curly brackets
Also, use curly brackets "{}" after your "if" statements, even when they're one liners. This also goes for "for" statements.
Luck,
CJSLChris S.
Difficult? This is Mission Impossible, not Mission Difficult. Difficult should be easy.
- 12-03-2008, 02:00 PM #4
Senior Member
- Join Date
- Jun 2008
- Posts
- 2,366
- Rep Power
- 7


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks