Results 1 to 5 of 5
  1. #1
    Join Date
    Jan 2011
    Posts
    27
    Rep Power
    0

    Default HELP!! New to Java!!

    Hi, I am not even sure if I am posting in the right area??

    Please help!!

    Java Code:
    
    public class Volume1
    {
      
        public static void main(String[] args)
    
        {
            
            
            
    
            int cansPerPack = 6;
            double canVolume = 0.355; // Litres in a 12 ounce can
            double packPrice = 10; // Price for 6 bottle pack
            int unitPrice = 2; // Price for each bottle
            import java.util.Scanner;
            Scanner in = new Scanner(System.in);
            int quantity = in.next.Int();
            
            System.out.print("A six-pack of 12 ounce cans contains ");
            System.out.print(cansPerPack * canVolume);
            System.out.println(" litres.");
            
            System.out.print("The price of a 6 bottle pack is ");
            System.out.print(packPrice);
            System.out.println(" dollars");
            System.out.print("You have purchased ");
            System.out.print(quantity);
            System.out.println(" bottles");
            System.out.print("The total amount of bottles you have bought are ");
            System.out.print(quantity);
            System.out.print( " and the total cost for your purchases are ");
            System.out.print(quantity * unitPrice);
            System.out.println(" dollars.");
            
        }
    
    }
    I seem to be getting an illegal start of expression?
    Can someone tell me where I am going wrong? This is one of my first pieces of code on Java.
    This is some of my uni work, and I need a user to just import what they require, or how many units / bottles they require.

    Many thanks in advance!!

    Daz.

  2. #2
    JavaHater is offline Senior Member
    Join Date
    Dec 2010
    Posts
    165
    Rep Power
    4

    Default

    put your import statement at the top of your code

  3. #3
    Petr's Avatar
    Petr is offline Senior Member
    Join Date
    Jan 2011
    Location
    Russia
    Posts
    620
    Rep Power
    4

    Default

    Hi I changed your code as follows
    Java Code:
    import java.util.Scanner;
    
    public class Volume1 {
    
        public static void main(String[] args) {
            int cansPerPack = 6;
            double canVolume = 0.355; // Litres in a 12 ounce can
            double packPrice = 10; // Price for 6 bottle pack
            int unitPrice = 2; // Price for each bottle
            Scanner in = new Scanner(System.in);
            int quantity = in.nextInt();
    
            System.out.print("A six-pack of 12 ounce cans contains ");
            System.out.print(cansPerPack * canVolume);
            System.out.println(" litres.");
    
            System.out.print("The price of a 6 bottle pack is ");
            System.out.print(packPrice);
            System.out.println(" dollars");
            System.out.print("You have purchased ");
            System.out.print(quantity);
            System.out.println(" bottles");
            System.out.print("The total amount of bottles you have bought are ");
            System.out.print(quantity);
            System.out.print( " and the total cost for your purchases are ");
            System.out.print(quantity * unitPrice);
            System.out.println(" dollars.");
        }
    }
    Skype: petrarsentev
    http://TrackStudio.com

  4. #4
    Join Date
    Jan 2011
    Posts
    27
    Rep Power
    0

    Default

    That is great!!

    Thank you so much for this!! :)

    Daz.

  5. #5
    hiroki is offline Member
    Join Date
    Jan 2011
    Posts
    2
    Rep Power
    0

    Default

    you should put the import sentence on the top of the codes

Posting Permissions

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