Use the random number generator to test the user\'s mathematical ability. Genera
ID: 3841391 • Letter: U
Question
Use the random number generator to test the user's mathematical ability.
Generate two random numbers (100 should be your seed for the random numbers).
Tell the user:
Let's play Are You Smarter Than a 5th Grader!!
What is the answer to the following math problem?
Display a math problem showing randNum1 X randNum2.
Get the user's answer.
Check to see if it is correct.
If it's correct, tell the user
Correct, your are smarter than a 5th grader!
Otherwise, tell the user they aren't smarter than a 5th grader and give them the correct answer to the problem.
** After you get that basic part of the program working, add a loop that generates 5 problems, asks for the answer, checks the answer and lets the user know if his/her answer is correct. **
Module 6 - RUSmarterThanAFifthGrader InstructionsUse the random number generator to test the user's mathematical ability.
Generate two random numbers (100 should be your seed for the random numbers).
Tell the user:
Let's play Are You Smarter Than a 5th Grader!!
What is the answer to the following math problem?
Display a math problem showing randNum1 X randNum2.
Get the user's answer.
Check to see if it is correct.
If it's correct, tell the user
Correct, your are smarter than a 5th grader!
Otherwise, tell the user they aren't smarter than a 5th grader and give them the correct answer to the problem.
** After you get that basic part of the program working, add a loop that generates 5 problems, asks for the answer, checks the answer and lets the user know if his/her answer is correct. **
Explanation / Answer
package smart;
import java.util.Random;
import java.util.Scanner;
public class RUSmarterThanAFifthGrader {
public static void main(String[] args) {
Random rand = new Random();
Scanner sc = new Scanner(System.in);
for(int i=0;i<5;i++){
int n1 = rand.nextInt(9) + 1;
int n2 = rand.nextInt(9) + 1;
int prod = n1*n2;
int r=0;
System.out.println("Enter the product of "+n1+"x"+n2+": ");
r=sc.nextInt();
if(r==prod)
System.out.println("Correct, your are smarter than a 5th grader!");
else
System.out.println("You aren't smarter than a 5th grader. Correct answer: "+prod);
}
sc.close();
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.