Compilation errors

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • tcby16
    New Member
    • Nov 2007
    • 3

    #1

    Compilation errors

    I am supposed to use two classes to perform one of three math operations depending on the user's choice. Use if statements to allow the user to choose which math operation to execute.

    So I created two files one file called Math and the other MathStart. Please see below.
    Must ‘if’ statements have an else? I think what is suppose to happen is, I prompt the user to see with choice they want to use and then whichever they choose that program is run.

    Here are the errors that I am getting for this program:

    C:\Documents and Settings\Triffe e\My Documents\Math3 16.java:83: ')' expected
    System.out.prin tln("You entered: "count + ", " + ++count + ", " + ++count + ", " + ++count+ ", and" + ++count);
    ^
    C:\Documents and Settings\Triffe e\My Documents\Math3 16.java:83: not a statement
    System.out.prin tln("You entered: "count + ", " + ++count + ", " + ++count + ", " + ++count+ ", and" + ++count);
    ^
    C:\Documents and Settings\Triffe e\My Documents\Math3 16.java:83: ';' expected


    import java.util.*;

    public class Math316
    {

    private static Scanner keyboard = new Scanner(System. in); //sets up things so program can have keyboard input

    public static void ProductOfTwoDou bles()
    {

    double d1, d2, answer; // declares variable type

    System.out.prin tln("Please enter any two numbers separated by a space."); //user prompts
    System.out.prin t("This program will multiply the numbers for you.");

    d1 = keyboard.nextDo uble(); //reads one double from the keyboard
    d2 = keyboard.nextDo uble();

    answer = d1 * d2;

    System.out.prin tln("You entered " + d1 + " and " + d2);
    System.out.prin tln("\n");
    System.out.prin tln("The product is: "+ answer + ".\n");



    } //end ProductOfTwoDou bles method

    public static void ThreeIntegers() ;

    private static Scanner keyboard = new Scanner(System. in); //sets up things so program can have keyboard input

    {
    int n1, n2, n3, sum; // declares variable type


    System.out.prin tln("Please enter 3 whole numbers separated by one or more spaces."); //user prompts
    System.out.prin t("This program will add the numbers for you.");

    n1 = keyboard.nextIn t(); //reads one int from the keyboard
    n2 = keyboard.nextIn t();
    n3 = keyboard.nextIn t();

    sum = n1 + n2 + n3;

    System.out.prin tln("You entered " + n1 + n2);
    System.out.prin tln(" and " + n3);
    System.out.prin tln("The sum is: "+ sum + ".\n");

    } //end ThreeIntegers method


    public static void CountPlusFive() ;

    private static Scanner keyboard = new Scanner(System. in); //sets up things so program can have keyboard input

    {

    int count;


    System.out.prin tln("Please enter one whole numbers."); //user prompts
    System.out.prin t("This program will display that number and the next five integers in sequence.");

    System.out.prin tln(count + ", " + ++count + ", " + ++count + ", " + ++count+ ", " + ++count+ ", " + ++count);

    count = keyboard.nextIn t(); //reads one int from the keyboard

    System.out.prin tln("You entered: "count + ", " + ++count + ", " + ++count + ", " + ++count+ ", and" + ++count);
    System.out.prin tln("\n");

    } //end CountPlusFive method

    } // brace - end Math316 Class


    *************** *************** *************** *************** ************
    Next file is below:--it has lots of errors


    C:\Documents and Settings\Triffe e\My Documents\MathS tart316.java:33 : cannot find symbol
    symbol : class Scanner
    location: class MathStart316
    Scanner keyboard = new Scanner(System. in);
    ^
    C:\Documents and Settings\Triffe e\My Documents\MathS tart316.java:33 : cannot find symbol
    symbol : class Scanner
    location: class MathStart316
    Scanner keyboard = new Scanner(System. in);
    ^
    C:\Documents and Settings\Triffe e\My Documents\MathS tart316.java:35 : cannot find symbol
    symbol : variable scannerObject
    location: class MathStart316
    choice1 = scannerObject.n extInt(); //reads one int form the keyboard
    ^
    C:\Documents and Settings\Triffe e\My Documents\MathS tart316.java:36 : cannot find symbol
    symbol : variable scannerObject
    location: class MathStart316
    choice2 = scannerObject.n extInt();
    ^
    C:\Documents and Settings\Triffe e\My Documents\MathS tart316.java:37 : cannot find symbol
    symbol : variable scannerObject
    location: class MathStart316
    choice3 = scannerObject.n extInt();
    ^
    C:\Documents and Settings\Triffe e\My Documents\MathS tart316.java:39 : cannot find symbol
    symbol : variable choice
    location: class MathStart316
    if (choice==1)
    ^
    .\Math316.java: 83: ')' expected
    System.out.prin tln("You entered: "count + ", " + ++count + ", " + ++count + ", " + ++count+ ", and" + ++count);
    ^
    .\Math316.java: 83: not a statement
    System.out.prin tln("You entered: "count + ", " + ++count + ", " + ++count + ", " + ++count+ ", and" + ++count);
    ^
    .\Math316.java: 83: ';' expected
    System.out.prin tln("You entered: "count + ", " + ++count + ", " + ++count + ", " + ++count+ ", and" + ++count);
    ^
    .\Math316.java: 44: keyboard is already defined in Math316
    private static Scanner keyboard = new Scanner(System. in); //sets up things so program can have keyboard input
    ^
    .\Math316.java: 69: keyboard is already defined in Math316
    private static Scanner keyboard = new Scanner(System. in); //sets up things so program can have keyboard input
    ^
    C:\Documents and Settings\Triffe e\My Documents\MathS tart316.java:42 : cannot find symbol
    symbol : variable choice
    location: class MathStart316
    if (choice==2)
    ^
    C:\Documents and Settings\Triffe e\My Documents\MathS tart316.java:45 : cannot find symbol
    symbol : variable choice
    location: class MathStart316
    if (choice==3)
    ^
    .\Math316.java: 42: missing method body, or declare abstract
    public static void ThreeIntegers() ;
    ^
    .\Math316.java: 67: missing method body, or declare abstract
    public static void CountPlusFive() ;
    ^
    15 errors

    Tool completed with exit code 1



    * This program menu will allow you to multiply, add, and count.
    Please choose from the one of the following by entering the
    number of your choice from the list below:


    1: Multiply two doubles
    2: Add three integers
    3: Count five numbers past your number

    *************** *************** *************** ************/

    public class MathStart316

    { /* brace - start of class MathStart316/
    /* public static makes the main method available to any user*/
    public static void main(String[] args)

    {

    int choice1, choice2, choice3;

    System.out.prin tln("Please enter the number of your choice:");

    Scanner keyboard = new Scanner(System. in);

    choice1 = scannerObject.n extInt(); //reads one int form the keyboard
    choice2 = scannerObject.n extInt();
    choice3 = scannerObject.n extInt();

    if (choice==1)
    Math316.Product OfTwoDoubles();

    if (choice==2)
    Math316.ThreeIn tegers();

    if (choice==3)
    Math316.CountPl usFive();

    }

    }
  • r035198x
    MVP
    • Sep 2006
    • 13225

    #2
    Originally posted by tcby16
    I am supposed to use two classes to perform one of three math operations depending on the user's choice. Use if statements to allow the user to choose which math operation to execute.

    So I created two files one file called Math and the other MathStart. Please see below.
    Must ‘if’ statements have an else? I think what is suppose to happen is, I prompt the user to see with choice they want to use and then whichever they choose that program is run.

    Here are the errors that I am getting for this program:

    C:\Documents and Settings\Triffe e\My Documents\Math3 16.java:83: ')' expected
    System.out.prin tln("You entered: "count + ", " + ++count + ", " + ++count + ", " + ++count+ ", and" + ++count);
    ^
    C:\Documents and Settings\Triffe e\My Documents\Math3 16.java:83: not a statement
    System.out.prin tln("You entered: "count + ", " + ++count + ", " + ++count + ", " + ++count+ ", and" + ++count);
    ^
    C:\Documents and Settings\Triffe e\My Documents\Math3 16.java:83: ';' expected


    import java.util.*;

    public class Math316
    {

    private static Scanner keyboard = new Scanner(System. in); //sets up things so program can have keyboard input

    public static void ProductOfTwoDou bles()
    {

    double d1, d2, answer; // declares variable type

    System.out.prin tln("Please enter any two numbers separated by a space."); //user prompts
    System.out.prin t("This program will multiply the numbers for you.");

    d1 = keyboard.nextDo uble(); //reads one double from the keyboard
    d2 = keyboard.nextDo uble();

    answer = d1 * d2;

    System.out.prin tln("You entered " + d1 + " and " + d2);
    System.out.prin tln("\n");
    System.out.prin tln("The product is: "+ answer + ".\n");



    } //end ProductOfTwoDou bles method

    public static void ThreeIntegers() ;

    private static Scanner keyboard = new Scanner(System. in); //sets up things so program can have keyboard input

    {
    int n1, n2, n3, sum; // declares variable type


    System.out.prin tln("Please enter 3 whole numbers separated by one or more spaces."); //user prompts
    System.out.prin t("This program will add the numbers for you.");

    n1 = keyboard.nextIn t(); //reads one int from the keyboard
    n2 = keyboard.nextIn t();
    n3 = keyboard.nextIn t();

    sum = n1 + n2 + n3;

    System.out.prin tln("You entered " + n1 + n2);
    System.out.prin tln(" and " + n3);
    System.out.prin tln("The sum is: "+ sum + ".\n");

    } //end ThreeIntegers method


    public static void CountPlusFive() ;

    private static Scanner keyboard = new Scanner(System. in); //sets up things so program can have keyboard input

    {

    int count;


    System.out.prin tln("Please enter one whole numbers."); //user prompts
    System.out.prin t("This program will display that number and the next five integers in sequence.");

    System.out.prin tln(count + ", " + ++count + ", " + ++count + ", " + ++count+ ", " + ++count+ ", " + ++count);

    count = keyboard.nextIn t(); //reads one int from the keyboard

    System.out.prin tln("You entered: "count + ", " + ++count + ", " + ++count + ", " + ++count+ ", and" + ++count);
    System.out.prin tln("\n");

    } //end CountPlusFive method

    } // brace - end Math316 Class


    *************** *************** *************** *************** ************
    Next file is below:--it has lots of errors


    C:\Documents and Settings\Triffe e\My Documents\MathS tart316.java:33 : cannot find symbol
    symbol : class Scanner
    location: class MathStart316
    Scanner keyboard = new Scanner(System. in);
    ^
    C:\Documents and Settings\Triffe e\My Documents\MathS tart316.java:33 : cannot find symbol
    symbol : class Scanner
    location: class MathStart316
    Scanner keyboard = new Scanner(System. in);
    ^
    C:\Documents and Settings\Triffe e\My Documents\MathS tart316.java:35 : cannot find symbol
    symbol : variable scannerObject
    location: class MathStart316
    choice1 = scannerObject.n extInt(); //reads one int form the keyboard
    ^
    C:\Documents and Settings\Triffe e\My Documents\MathS tart316.java:36 : cannot find symbol
    symbol : variable scannerObject
    location: class MathStart316
    choice2 = scannerObject.n extInt();
    ^
    C:\Documents and Settings\Triffe e\My Documents\MathS tart316.java:37 : cannot find symbol
    symbol : variable scannerObject
    location: class MathStart316
    choice3 = scannerObject.n extInt();
    ^
    C:\Documents and Settings\Triffe e\My Documents\MathS tart316.java:39 : cannot find symbol
    symbol : variable choice
    location: class MathStart316
    if (choice==1)
    ^
    .\Math316.java: 83: ')' expected
    System.out.prin tln("You entered: "count + ", " + ++count + ", " + ++count + ", " + ++count+ ", and" + ++count);
    ^
    .\Math316.java: 83: not a statement
    System.out.prin tln("You entered: "count + ", " + ++count + ", " + ++count + ", " + ++count+ ", and" + ++count);
    ^
    .\Math316.java: 83: ';' expected
    System.out.prin tln("You entered: "count + ", " + ++count + ", " + ++count + ", " + ++count+ ", and" + ++count);
    ^
    .\Math316.java: 44: keyboard is already defined in Math316
    private static Scanner keyboard = new Scanner(System. in); //sets up things so program can have keyboard input
    ^
    .\Math316.java: 69: keyboard is already defined in Math316
    private static Scanner keyboard = new Scanner(System. in); //sets up things so program can have keyboard input
    ^
    C:\Documents and Settings\Triffe e\My Documents\MathS tart316.java:42 : cannot find symbol
    symbol : variable choice
    location: class MathStart316
    if (choice==2)
    ^
    C:\Documents and Settings\Triffe e\My Documents\MathS tart316.java:45 : cannot find symbol
    symbol : variable choice
    location: class MathStart316
    if (choice==3)
    ^
    .\Math316.java: 42: missing method body, or declare abstract
    public static void ThreeIntegers() ;
    ^
    .\Math316.java: 67: missing method body, or declare abstract
    public static void CountPlusFive() ;
    ^
    15 errors

    Tool completed with exit code 1



    * This program menu will allow you to multiply, add, and count.
    Please choose from the one of the following by entering the
    number of your choice from the list below:


    1: Multiply two doubles
    2: Add three integers
    3: Count five numbers past your number

    *************** *************** *************** ************/

    public class MathStart316

    { /* brace - start of class MathStart316/
    /* public static makes the main method available to any user*/
    public static void main(String[] args)

    {

    int choice1, choice2, choice3;

    System.out.prin tln("Please enter the number of your choice:");

    Scanner keyboard = new Scanner(System. in);

    choice1 = scannerObject.n extInt(); //reads one int form the keyboard
    choice2 = scannerObject.n extInt();
    choice3 = scannerObject.n extInt();

    if (choice==1)
    Math316.Product OfTwoDoubles();

    if (choice==2)
    Math316.ThreeIn tegers();

    if (choice==3)
    Math316.CountPl usFive();

    }

    }
    1.) Use code tags when posting code
    2.) Use thread titles that best escribe your problem
    3.) Read the error messages carefully. They tell you what the problem is. e.g If Scanner cannot be resolved then maybe you didn't import the java.util.Scann er class

    Comment

    • tcby16
      New Member
      • Nov 2007
      • 3

      #3
      Ok, I made some changes. I am down to 1 complilation error and I can't figure out what to do.

      Here is the error message:

      C:\Documents and Settings\Triffe e\My Documents\Math3 16.java:87: reached end of file while parsing
      } //end CountPlusFive method
      ^
      1 error

      Tool completed with exit code 1


      I have also attached the MathStart316 class below this one.




      /* This program has two classes: Math316.java & MathStart316.ja va.
      MathStart316.ja va contains the main method and also the 'if' statements
      whereas Math316.java has three methods. The methods are: ProductOfTwoDou bles,
      ThreeIntegers and CountPlusFive. */

      import java.util.*;

      public class Math316
      {

      private static Scanner keyboard = new Scanner(System. in); //sets up things so program can have keyboard input

      public static void ProductOfTwoDou bles()
      {

      double d1, d2, answer; // declares variable type

      System.out.prin tln("Please enter any two numbers separated by a space."); //user prompts
      System.out.prin t("This program will multiply the numbers for you.");

      d1 = keyboard.nextDo uble(); //reads one double from the keyboard
      d2 = keyboard.nextDo uble();

      answer = d1 * d2;

      System.out.prin tln("You entered " + d1 + " and " + d2);
      System.out.prin tln("\n");
      System.out.prin tln("The product is: "+ answer + ".\n");



      } //end ProductOfTwoDou bles method

      public static void ThreeIntegers() ;
      {

      /*brace - start of friendName method*/

      int n1, n2, n3, sum; // declares variable type


      System.out.prin tln("Please enter 3 whole numbers separated by one or more spaces."); //user prompts
      System.out.prin t("This program will add the numbers for you.");

      n1 = keyboard.nextIn t(); //reads one int from the keyboard
      n2 = keyboard.nextIn t();
      n3 = keyboard.nextIn t();

      sum = n1 + n2 + n3;

      System.out.prin tln("You entered " + n1 + n2);
      System.out.prin tln(" and " + n3);
      System.out.prin tln("The sum is: "+ sum + ".\n");

      } //end ThreeIntegers method


      public static void CountPlusFive() ;


      { /*brace - start of friendName method*/

      int count=0;
      char s= count + ", " + ++count + ", " + ++count + ", " + ++count+ ", " + ++count+ ", " + ++count;

      System.out.prin tln("Please enter one whole numbers."); //user prompts
      System.out.prin t("This program will display that number and the next five integers in sequence.");
      System.out.prin tln("You entered " + s);


      for (int i=0;i<=5;i++)
      {
      if (name.charAt(i) !=s.charAt(i)) {
      count++;
      }

      System.out.prin tln("\n");

      } //end CountPlusFive method

      // brace - end Math316 Class

      _______________ _______________ _______________ _______________ ____
      _______________ _______________ _______________ _______________ ____


      * This program menu will allow you to multiply, add, and count.
      Please choose from the one of the following by entering the
      number of your choice from the list below:


      1: Multiply two doubles
      2: Add three integers
      3: Count five numbers past your number

      *************** *************** *************** ************/

      public class MathStart316

      { /* brace - start of class MathStart316/
      /* public static makes the main method available to any user*/
      public static void math316(String[] args)

      {

      int choice1, choice2, choice3;


      System.out.prin tln("Please enter the number of your choice:");



      if (choice1==1)
      Math316.Product OfTwoDoubles();

      if (choice2==2)
      Math316.ThreeIn tegers();

      if (choice3==3)
      Math316.CountPl usFive();

      }

      }

      Comment

      • JosAH
        Recognized Expert MVP
        • Mar 2007
        • 11453

        #4
        Originally posted by tcby16
        Ok, I made some changes. I am down to 1 complilation error and I can't figure out what to do.

        Here is the error message:

        C:\Documents and Settings\Triffe e\My Documents\Math3 16.java:87: reached end of file while parsing
        } //end CountPlusFive method
        ^
        1 error

        Tool completed with exit code 1
        The javac compiler was happily parsing away and all of a sudden the input was
        exhausted. That's what it was trying to tell you. Most likely you're missing one
        or more right curly brackets at the end of your program text.

        kind regards,

        Jos

        Comment

        • tcby16
          New Member
          • Nov 2007
          • 3

          #5
          I guess I need to ask what is "parsing".

          I have added brackets at the end and I am still getting this error.

          Is my program good otherwise?

          Comment

          • r035198x
            MVP
            • Sep 2006
            • 13225

            #6
            Originally posted by tcby16
            I guess I need to ask what is "parsing".

            I have added brackets at the end and I am still getting this error.

            Is my program good otherwise?
            Don't just add a bracket. Try to figure out where it's needed.
            A good way of checking correctness of your program structure is to indent your code.

            You have a line in your code which reads

            [CODE=java] public static void ThreeIntegers() ;[/CODE] which you put inside a class. What is it supposed to do there?

            Comment

            Working...