Results 1 to 4 of 4

Thread: Need Help

  1. #1
    maggie_2 is offline Member
    Join Date
    Sep 2008
    Posts
    9
    Rep Power
    0

    Default 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"); 
    
    
    }

  2. #2
    CJSLMAN's Avatar
    CJSLMAN is offline Moderator
    Join Date
    Oct 2008
    Location
    Mexico
    Posts
    1,159
    Rep Power
    7

    Default setFlavor method?

    I don't see the implementation of the setFlavor() method that's being called from the IceCreamCone constructor.

    CJSL
    Chris S.
    Difficult? This is Mission Impossible, not Mission Difficult. Difficult should be easy.

  3. #3
    CJSLMAN's Avatar
    CJSLMAN is offline Moderator
    Join Date
    Oct 2008
    Location
    Mexico
    Posts
    1,159
    Rep Power
    7

    Default Curly brackets

    Also, use curly brackets "{}" after your "if" statements, even when they're one liners. This also goes for "for" statements.

    Luck,
    CJSL
    Chris S.
    Difficult? This is Mission Impossible, not Mission Difficult. Difficult should be easy.

  4. #4
    masijade is offline Senior Member
    Join Date
    Jun 2008
    Posts
    2,571
    Rep Power
    9

    Default

    You're first problem though is that you are performing actions in the class definition. Place those "showWhateverDialog" lines inside a method, not directly in the class definition like that.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •