Java gurus, why won't my program compile? v. very basic

Discussion in 'OT Technology' started by springy101, Sep 11, 2008.

  1. springy101

    springy101 When god comes and calls me to his kingdom, I'll t

    Joined:
    Jul 10, 2006
    Messages:
    10,928
    Likes Received:
    0
    Location:
    Sacramento, CA
    I'm in the 3rd week of my Intro to Java class, and the assignment was make a program for a supermarket to compute the price per unit depending on weight. I thought I had it all down but I keep getting illegal start of expression errors.

    Here is the code:

    import java.util.scanner;

    public class UnitPrice;
    {


    public static void main (String [] args);

    {

    Scanner keybord = new scanner (System.in);

    float name;
    float price;
    float pounds;
    float ounces;
    float weightinounces;
    float priceperounce;
    float unitprice;

    System.out.print ("Enter Name");
    name = keyboard.nextFloat + ();

    System.out.print ("Enter Price");
    priceperounce = keyboard.nextFloat + ();

    System.out.print ("Enter Weight (lbs)");
    pounds = keyboard.nextFloat + ();

    System.out.print ("Enter Weight (oz)");
    ounces = keyboard.nextFloat + ();

    weightinounces = (pounds * 16f + ounces);

    unitprice = weightinpounds * pricerperounce;

    System.out.println ("The price is" + unitprice);

    }

    }

    and here is a screenshot of Jgrasp:

    http://moarpics.com/images/caly8j0txnajhmh5k4l.jpg

    Linked because it's a little big. Halp?
     
  2. deusexaethera

    deusexaethera OT Supporter

    Joined:
    Jan 27, 2005
    Messages:
    19,712
    Likes Received:
    0
    Repost it inside code tags, so you can keep the indentations.
     
  3. skinjob

    skinjob Active Member

    Joined:
    Jan 6, 2001
    Messages:
    2,337
    Likes Received:
    0
    Location:
    Aztlán
    It's telling you that it expected a '{' character instead of the ';' character that it's pointing to. Since it didn't get the character it expected, whatever follows is meaningless to the compiler.
     
  4. StevesVR4

    StevesVR4 Get Arrested

    Joined:
    Jul 1, 2003
    Messages:
    7,328
    Likes Received:
    0
    Your syntax problem is this:
    Code:
    public class UnitPrice[color=red];[/color]
    {
        public static void main (String [] args)[color=red];[/color]
        {
            ...
        }
    }
    
    You don't put semi-colons after the class declaration or method declaration.
     

Share This Page