Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 5 of 5

Thread: 3 script errors in my code

  1. #1
    Junior Member
    Join Date
    Jun 2014
    Posts
    2
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default 3 script errors in my code

    Hello everyone,

    I need to write a simple program. After I input the cost of an entree, drink, and dessert, it should calculate the cost of a meal and its tax. However, when I compile my code, I get three errors. Can you tell me what's wrong and how I can fix it?

    Here are the errors I get:

    foodcalc.java:1: error: ';' expected
    import java.io.*
    ^
    foodcalc.java:2: error: ';' expected
    import java.util.Scanner
    ^
    foodcalc.java:13: error: ';' expected
    systemout.println ("Enter price of dessert")
    ^
    3 errors

    _______________________
    And here is my code:
    import java.io.*
    import java.util.Scanner
    public class foodcalc
     
    {
      public static void main (String [] args)
      {
      Scanner input = new Scanner (System.in);
      systemout.println ("Enter price of entree");
      double entreeCost = input.nextdouble ();
      systemout.println ("Enter price of drink");
      double drinkCost = input.nextdouble ();
      systemout.println ("Enter price of dessert")
      double dessertCost = input.nextdouble ();
     
      double foodCost = entreeCost + drinkCost + dessertCost;
      double taxAmt = foodCost * 0.10 ;
     
    System.out.println ("Total cost is $ " + (int)(mealCost * 100 /100.0));
     
      }
    }
    Last edited by aniperi; June 15th, 2014 at 04:31 PM. Reason: formatted


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: 3 script errors in my code

    error: ';' expected
    The compiler was expecting a ; before what it found. Make sure the previous statement has an ending ;

    Please edit your post and wrap your code with code tags:
    [code=java]
    YOUR CODE GOES HERE
    [/code]
    to get highlighting and preserve formatting.
    If you don't understand my answer, don't ignore it, ask a question.

  3. The Following User Says Thank You to Norm For This Useful Post:

    aniperi (June 15th, 2014)

  4. #3
    Senior Member
    Join Date
    Jul 2013
    Location
    Europe
    Posts
    666
    Thanks
    0
    Thanked 121 Times in 105 Posts

    Default Re: 3 script errors in my code

    Just read the error message:
    foodcalc.java:1: error: ';' expected
    It says quite clearly, that it expects a semicolon.

  5. The Following User Says Thank You to Cornix For This Useful Post:

    aniperi (June 15th, 2014)

  6. #4
    Junior Member
    Join Date
    Jun 2014
    Posts
    2
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default Re: 3 script errors in my code

     
    import java.io.*;
    import java.util.Scanner;
    public class foodcalc
     
    {
      public static void main (String [] args)
      {
      Scanner input = new Scanner (System.in);
      systemout.println ("Enter price of entree");
      double entreeCost = input.nextdouble ();
      systemout.println ("Enter price of drink");
      double drinkCost = input.nextdouble ();
      systemout.println ("Enter price of dessert");
      double dessertCost = input.nextdouble ();
     
      double foodCost = entreeCost + drinkCost + dessertCost;
      double taxAmt = foodCost * 0.10 ;
     
    System.out.println ("Total cost is $ " + (int)(mealCost * 100 /100.0));
     
    }
    }

    _____________
    After editing my code, it looks like the above^^. However, now I get 7 new errors:

    foodcalc.java:9: error: cannot find symbol
    systemout.println ("Enter price of entree");
    ^
    symbol: variable systemout
    location: class foodcalc
    foodcalc.java:10: error: cannot find symbol
    double entreeCost = input.nextdouble ();
    ^
    symbol: method nextdouble()
    location: variable input of type Scanner
    foodcalc.java:11: error: cannot find symbol
    systemout.println ("Enter price of drink");
    ^
    symbol: variable systemout
    location: class foodcalc
    foodcalc.java:12: error: cannot find symbol
    double drinkCost = input.nextdouble ();
    ^
    symbol: method nextdouble()
    location: variable input of type Scanner
    foodcalc.java:13: error: cannot find symbol
    systemout.println ("Enter price of dessert");
    ^
    symbol: variable systemout
    location: class foodcalc
    foodcalc.java:14: error: cannot find symbol
    double dessertCost = input.nextdouble ();
    ^
    symbol: method nextdouble()
    location: variable input of type Scanner
    foodcalc.java:19: error: cannot find symbol
    System.out.println ("Total cost is $ " + (int)(mealCost * 100 /100.0));
    ^
    symbol: variable mealCost
    location: class foodcalc
    7 errors
    ____________________
    How do I declare the system.out variable? I thought system.out is part of a string, and not a variable to be declared.

  7. #5
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: 3 script errors in my code

    How do I declare the system.out variable
    System.out is the syntax for referring to the static variable: out in the System class.

    Java is case sensitive. You need to check the spelling for any java classes or methods you use.

    See the API doc for correct spellings: http://docs.oracle.com/javase/7/docs/api/index.html
    If you don't understand my answer, don't ignore it, ask a question.

  8. The Following User Says Thank You to Norm For This Useful Post:

    aniperi (June 15th, 2014)

Similar Threads

  1. Replies: 7
    Last Post: May 8th, 2014, 12:51 PM
  2. Please help with this java script code so it validates.?
    By robemeen in forum Other Programming Languages
    Replies: 1
    Last Post: March 3rd, 2014, 04:08 PM
  3. Replies: 3
    Last Post: April 27th, 2013, 07:19 AM
  4. Code is giving an error in console, but there are no errors apparent in the code!
    By JamEngulfer221 in forum What's Wrong With My Code?
    Replies: 2
    Last Post: November 15th, 2011, 09:30 PM
  5. Need Java code to be used in Selenium Script
    By anujbatta in forum What's Wrong With My Code?
    Replies: 1
    Last Post: May 25th, 2011, 10:50 AM