Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a math program. The program should allow the to enter how many questions t

ID: 3648949 • Letter: W

Question

Write a math program. The program should allow the to enter how many questions they want to answer. It should then produce that number of addition questions, for example, 2 + 3. The number for each question should be generated randomly. You decide the range for the numbers. The program should allow the user three tries at getting the correct response. If the user gets the correct response, the program should output a message stating it was correct and how many tries it took. If the user does not get the correct response in three tries, the correct answer should be displayed with an appropriate message. At the end of the review, a message should be displayed specifying how many questions were answered correctly

Explanation / Answer

solution: import java.io.*; import java.util.Random; public class math { //----------------------------------------------------------------- // Generates random numbers //----------------------------------------------------------------- public static void main (String[] args)throws IOException { DataInputStream stdin = new DataInputStream (System.in); Random generator = new Random(); int num1; int num2; int guess; int answer; String string1; num1 = generator.nextInt(13); //Gets random num1 num2 = generator.nextInt(13); //Gets Random num2 System.out.println ("what is " + num1 + "*" + num2); string1 = stdin.readLine(); guess = Integer.parseInt(string1); answer = (num1 * num2); if (guess == answer) { //Begin if bracket System.out.println("Very good, the correct answer is " + answer); } //End if Bracket else { //Begin Else Brakcets System.out.println("Guess again"); } //End Else brackets } } //Close MAIN bracket } //Close CLASS MATH bracket

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote