• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

5 errors found in my program.

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 five script errors. Can you tell me what's wrong and how I can fix it?

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 extraCost = input.nextdouble ();
systemout.prinln ("Enter price of drink");
double extraCost = input.nextdouble ();
systemout.println ("Enter price of dessert")
double extraCost = input.nextdouble ();

double foodCost = entreeCost + drinkCost + dessertCost;
double taxAmt = foodCost * 0.10 ;

System.out.println ("Total cost is $ " + (int)(mealCost * 100 /100.0);
 
Rancher
Posts: 43081
77
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Welcome to JavaRanch.

Please post the error messages you're getting. If what you posted is all the code you have, then you're missing a closing parenthesis for the last "System.out.println" statement, a closing bracket for the main method and a closing bracket for the class definition. Start by adding those, and see what the compiler says then.
 
Rancher
Posts: 3742
16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It would help if you told us what the errors are but a couple of things I can see are
  • You haven't declared the systemout, entreeCost, drinkCost or dessertCost variables.
  • You've declared the extraCost variable three times.
  •  
    ani peri
    Greenhorn
    Posts: 3
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    Okay I've fixed it, and now I'm down to two errors. I'm not sure how to declare the variable for system.out; how would i go about doing that?

    Here are the errors I get:

    foodcalc.java:1: error: ';' expected
    import java.io.*
    ^
    foodcalc.java:2: error: ';' expected
    import java.util.Scanner
    ^

    2 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));

    }
    }
     
    Ulf Dittmer
    Rancher
    Posts: 43081
    77
    • Likes 1
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    It's not called "systemout", it's called "System.out", like you already have further down in the code.

    As to the imports, put a semi-colon after them. Every statement in Java needs to be ended with a semi-colon.
     
    ani peri
    Greenhorn
    Posts: 3
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    Thank you! Now that I've fixed those errors, I get 7 new errors suddenly:

    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

    I'm not sure what to do from here. My first thought is that I should declare mealCost like this:

    double mealCost = entreeCost+drinkCost+dessertCost;

    Aside from that, I don't know what to do.
     
    Bartender
    Posts: 2236
    63
    IntelliJ IDE Firefox Browser Spring Java Linux
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    1. Java compiler can't figure out what do you mean by systemout.
    Replace systemout with System.out and it should work.

    2. Java compiler can't find a method nextdouble in Scanner class. And it is right because there is no such method. There is one called nextDouble.
    Remember Java is case sensitive.

    3. Yes, you are right. You should declare a variable named mealCost if you want to print it. Your declaration looks fine.
    But one thing to consider. You already have a variable named foodCost. Isn't it what you want?

    4. I don't understand what your intent is in this piece of code:
    (int)(mealCost * 100 /100.0)

    Can you explain what you want to achieve?
     
    With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
    reply
      Bookmark Topic Watch Topic
    • New Topic