Skip to Main Content

New to Java

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

multiplication program

807601Mar 27 2008 — edited Mar 28 2008
okay new assignment
<-------------------------------------------------------------------------------------------------------------------------------->
Computers are playing an increasing role in education. Write a program that will help an elementary school student learn multiplication. Use a Random object to produce two positive one-digit integers. The program should then prompt the user with a question, such as

How much is 6 times 7?

The student then inputs the answer. Next, the program checks the student?s answer. If it is correct, display the message ?Very good!? and ask another multiplication question. If the answer is wrong, display the message ?No. Please try again.? and let the student try the same question repeatedly until the student finally gets it right. A separate method should be used to generate each new question. This method should be called once when the application begins execution and each time the user answers the question correctly.
<-------------------------------------------------------------------------------------------------------------------------------->

Below is what I have come up with but I get 17 errors which are
<-------------------------------------------------------------------------------------------------------------------------------->
F:\Javawork\Multiplication\Multiplication.java:22: <identifier> expected
System.out.println("How much is "); int = Number1 (" TIMES "); int = Number2 (" ? ");
^
F:\Javawork\Multiplication\Multiplication.java:22: illegal start of type
System.out.println("How much is "); int = Number1 (" TIMES "); int = Number2 (" ? ");
^
F:\Javawork\Multiplication\Multiplication.java:22: <identifier> expected
System.out.println("How much is "); int = Number1 (" TIMES "); int = Number2 (" ? ");
^
F:\Javawork\Multiplication\Multiplication.java:22: <identifier> expected
System.out.println("How much is "); int = Number1 (" TIMES "); int = Number2 (" ? ");
^
F:\Javawork\Multiplication\Multiplication.java:23: <identifier> expected
UserAnswer = input.nextInt();
^
F:\Javawork\Multiplication\Multiplication.java:26: illegal start of type
if ( int = UserAnswer == int = ActualAnswer ) // if answer is correct
^
F:\Javawork\Multiplication\Multiplication.java:26: <identifier> expected
if ( int = UserAnswer == int = ActualAnswer ) // if answer is correct
^
F:\Javawork\Multiplication\Multiplication.java:26: ';' expected
if ( int = UserAnswer == int = ActualAnswer ) // if answer is correct
^
F:\Javawork\Multiplication\Multiplication.java:26: illegal start of type
if ( int = UserAnswer == int = ActualAnswer ) // if answer is correct
^
F:\Javawork\Multiplication\Multiplication.java:26: <identifier> expected
if ( int = UserAnswer == int = ActualAnswer ) // if answer is correct
^
F:\Javawork\Multiplication\Multiplication.java:26: ';' expected
if ( int = UserAnswer == int = ActualAnswer ) // if answer is correct
^
F:\Javawork\Multiplication\Multiplication.java:30: illegal start of type
if ( int = UserAnswer != int = ActualAnswer ) // if answer is not correct
^
F:\Javawork\Multiplication\Multiplication.java:30: <identifier> expected
if ( int = UserAnswer != int = ActualAnswer ) // if answer is not correct
^
F:\Javawork\Multiplication\Multiplication.java:30: ';' expected
if ( int = UserAnswer != int = ActualAnswer ) // if answer is not correct
^
F:\Javawork\Multiplication\Multiplication.java:30: illegal start of type
if ( int = UserAnswer != int = ActualAnswer ) // if answer is not correct
^
F:\Javawork\Multiplication\Multiplication.java:30: <identifier> expected
if ( int = UserAnswer != int = ActualAnswer ) // if answer is not correct
^
F:\Javawork\Multiplication\Multiplication.java:30: ';' expected
if ( int = UserAnswer != int = ActualAnswer ) // if answer is not correct
^
17 errors

Tool completed with exit code 1
<-------------------------------------------------------------------------------------------------------------------------------->

any ideas on how to fix?
 
public class Multiplication {
	public static void main (String[] args)
{

int Number1 = 0;
int Number2 = 0;
int ActualAnswer = 0;
int UserAnwer;

Number1 = (int)(Math.random() * 9 +1);
Number2 = (int)(Math.random() * 9 +1);
ActualAnswer = Number1 * Number2;
}

// get answer from user
Scanner input = new Scanner (System.in);
System.out.println("How much is "); int = Number1 (" TIMES "); int = Number2 (" ? ");
UserAnswer = input.nextInt();

// check answer
if ( int = UserAnswer == int = ActualAnswer ) // if answer is correct
{
System.out.printf( "Very Good!");
}
if ( int = UserAnswer != int = ActualAnswer ) // if answer is not correct
{
System.out.printf( "No. Please try again.");

} // end
}
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Apr 25 2008
Added on Mar 27 2008
18 comments
1,129 views