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();
}
}
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();
}
}
Comment