By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,222 Members | 1,395 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,222 IT Pros & Developers. It's quick & easy.

Compilation errors

P: 3
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\Triffee\My Documents\Math316.java:83: ')' expected
System.out.println("You entered: "count + ", " + ++count + ", " + ++count + ", " + ++count+ ", and" + ++count);
^
C:\Documents and Settings\Triffee\My Documents\Math316.java:83: not a statement
System.out.println("You entered: "count + ", " + ++count + ", " + ++count + ", " + ++count+ ", and" + ++count);
^
C:\Documents and Settings\Triffee\My Documents\Math316.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 ProductOfTwoDoubles()
{

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

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

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

answer = d1 * d2;

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



} //end ProductOfTwoDoubles 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.println("Please enter 3 whole numbers separated by one or more spaces."); //user prompts
System.out.print("This program will add the numbers for you.");

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

sum = n1 + n2 + n3;

System.out.println("You entered " + n1 + n2);
System.out.println(" and " + n3);
System.out.println("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.println("Please enter one whole numbers."); //user prompts
System.out.print("This program will display that number and the next five integers in sequence.");

System.out.println(count + ", " + ++count + ", " + ++count + ", " + ++count+ ", " + ++count+ ", " + ++count);

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

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

} //end CountPlusFive method

} // brace - end Math316 Class


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


C:\Documents and Settings\Triffee\My Documents\MathStart316.java:33: cannot find symbol
symbol : class Scanner
location: class MathStart316
Scanner keyboard = new Scanner(System.in);
^
C:\Documents and Settings\Triffee\My Documents\MathStart316.java:33: cannot find symbol
symbol : class Scanner
location: class MathStart316
Scanner keyboard = new Scanner(System.in);
^
C:\Documents and Settings\Triffee\My Documents\MathStart316.java:35: cannot find symbol
symbol : variable scannerObject
location: class MathStart316
choice1 = scannerObject.nextInt(); //reads one int form the keyboard
^
C:\Documents and Settings\Triffee\My Documents\MathStart316.java:36: cannot find symbol
symbol : variable scannerObject
location: class MathStart316
choice2 = scannerObject.nextInt();
^
C:\Documents and Settings\Triffee\My Documents\MathStart316.java:37: cannot find symbol
symbol : variable scannerObject
location: class MathStart316
choice3 = scannerObject.nextInt();
^
C:\Documents and Settings\Triffee\My Documents\MathStart316.java:39: cannot find symbol
symbol : variable choice
location: class MathStart316
if (choice==1)
^
.\Math316.java:83: ')' expected
System.out.println("You entered: "count + ", " + ++count + ", " + ++count + ", " + ++count+ ", and" + ++count);
^
.\Math316.java:83: not a statement
System.out.println("You entered: "count + ", " + ++count + ", " + ++count + ", " + ++count+ ", and" + ++count);
^
.\Math316.java:83: ';' expected
System.out.println("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\Triffee\My Documents\MathStart316.java:42: cannot find symbol
symbol : variable choice
location: class MathStart316
if (choice==2)
^
C:\Documents and Settings\Triffee\My Documents\MathStart316.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.println("Please enter the number of your choice:");

Scanner keyboard = new Scanner(System.in);

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

if (choice==1)
Math316.ProductOfTwoDoubles();

if (choice==2)
Math316.ThreeIntegers();

if (choice==3)
Math316.CountPlusFive();

}

}
Nov 8 '07 #1
Share this Question
Share on Google+
5 Replies


10K+
P: 13,264
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\Triffee\My Documents\Math316.java:83: ')' expected
System.out.println("You entered: "count + ", " + ++count + ", " + ++count + ", " + ++count+ ", and" + ++count);
^
C:\Documents and Settings\Triffee\My Documents\Math316.java:83: not a statement
System.out.println("You entered: "count + ", " + ++count + ", " + ++count + ", " + ++count+ ", and" + ++count);
^
C:\Documents and Settings\Triffee\My Documents\Math316.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 ProductOfTwoDoubles()
{

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

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

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

answer = d1 * d2;

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



} //end ProductOfTwoDoubles 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.println("Please enter 3 whole numbers separated by one or more spaces."); //user prompts
System.out.print("This program will add the numbers for you.");

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

sum = n1 + n2 + n3;

System.out.println("You entered " + n1 + n2);
System.out.println(" and " + n3);
System.out.println("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.println("Please enter one whole numbers."); //user prompts
System.out.print("This program will display that number and the next five integers in sequence.");

System.out.println(count + ", " + ++count + ", " + ++count + ", " + ++count+ ", " + ++count+ ", " + ++count);

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

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

} //end CountPlusFive method

} // brace - end Math316 Class


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


C:\Documents and Settings\Triffee\My Documents\MathStart316.java:33: cannot find symbol
symbol : class Scanner
location: class MathStart316
Scanner keyboard = new Scanner(System.in);
^
C:\Documents and Settings\Triffee\My Documents\MathStart316.java:33: cannot find symbol
symbol : class Scanner
location: class MathStart316
Scanner keyboard = new Scanner(System.in);
^
C:\Documents and Settings\Triffee\My Documents\MathStart316.java:35: cannot find symbol
symbol : variable scannerObject
location: class MathStart316
choice1 = scannerObject.nextInt(); //reads one int form the keyboard
^
C:\Documents and Settings\Triffee\My Documents\MathStart316.java:36: cannot find symbol
symbol : variable scannerObject
location: class MathStart316
choice2 = scannerObject.nextInt();
^
C:\Documents and Settings\Triffee\My Documents\MathStart316.java:37: cannot find symbol
symbol : variable scannerObject
location: class MathStart316
choice3 = scannerObject.nextInt();
^
C:\Documents and Settings\Triffee\My Documents\MathStart316.java:39: cannot find symbol
symbol : variable choice
location: class MathStart316
if (choice==1)
^
.\Math316.java:83: ')' expected
System.out.println("You entered: "count + ", " + ++count + ", " + ++count + ", " + ++count+ ", and" + ++count);
^
.\Math316.java:83: not a statement
System.out.println("You entered: "count + ", " + ++count + ", " + ++count + ", " + ++count+ ", and" + ++count);
^
.\Math316.java:83: ';' expected
System.out.println("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\Triffee\My Documents\MathStart316.java:42: cannot find symbol
symbol : variable choice
location: class MathStart316
if (choice==2)
^
C:\Documents and Settings\Triffee\My Documents\MathStart316.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.println("Please enter the number of your choice:");

Scanner keyboard = new Scanner(System.in);

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

if (choice==1)
Math316.ProductOfTwoDoubles();

if (choice==2)
Math316.ThreeIntegers();

if (choice==3)
Math316.CountPlusFive();

}

}
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.Scanner class
Nov 8 '07 #2

P: 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\Triffee\My Documents\Math316.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.java.
MathStart316.java contains the main method and also the 'if' statements
whereas Math316.java has three methods. The methods are: ProductOfTwoDoubles,
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 ProductOfTwoDoubles()
{

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

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

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

answer = d1 * d2;

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



} //end ProductOfTwoDoubles method

public static void ThreeIntegers();
{

/*brace - start of friendName method*/

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


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

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

sum = n1 + n2 + n3;

System.out.println("You entered " + n1 + n2);
System.out.println(" and " + n3);
System.out.println("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.println("Please enter one whole numbers."); //user prompts
System.out.print("This program will display that number and the next five integers in sequence.");
System.out.println("You entered " + s);


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

System.out.println("\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.println("Please enter the number of your choice:");



if (choice1==1)
Math316.ProductOfTwoDoubles();

if (choice2==2)
Math316.ThreeIntegers();

if (choice3==3)
Math316.CountPlusFive();

}

}
Nov 9 '07 #3

Expert 10K+
P: 11,448
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\Triffee\My Documents\Math316.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
Nov 9 '07 #4

P: 3
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?
Nov 9 '07 #5

10K+
P: 13,264
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

Expand|Select|Wrap|Line Numbers
  1.  public static void ThreeIntegers();
which you put inside a class. What is it supposed to do there?
Nov 10 '07 #6

Post your reply

Sign in to post your reply or Sign up for a free account.