Question: Using Java: Please follow requirements: -Use random-number generation to choose a number from 1 to 4 that will be used to select one of the
Using Java:

Please follow requirements:
-Use random-number generation to choose a number from 1 to 4 that will be used to select one of the four appropriate responses to each correct or incorrect answer. Use a switch statement to issue the responses.
- The program shall generate random numbers with a SecureRandom object
- The program shall ask the student to solve a multiplication problem
- A multiplication problem shall contain two numbers sampled from a uniform random distribution in the range of 0 to 9 (inclusive)
- The program shall display a random positive message if the student provides a correct response
- The program shall display a random negative message if the student provides an incorrect response
- The program shall terminate when a correct response is provided by the student
- The program shall continue to ask the student to solve the original multiplication problem until the student provides the correct answer
- Create a method called "quiz" that contains the program logic
- Create a function called "askQuestion" that prints the problem to the screen
- Create a function called "readResponse" that reads the answer from the student
- Create a function called "isAnswerCorrect" that checks to see if the student's answer matches the correct answer to the problem
- Create a function called "displayCorrectResponse" that prints out the response when a student enters a correct answer
- Create a function called "displayIncorrectResponse" that prints out the response when a student enters an incorrect answer
- Part 1: Create a main method that runs your program by calling the "quiz" method
##Code from Part 1:##
import java.util.*;
public class Quiz { public static void main(String[] args) { quiz(); }
public static void quiz() { Random rand = new Random();
int num1 = rand.nextInt(10); int num2 = rand.nextInt(10);
while (true) { int val1 = askQuestion(num1, num2); int val2 = readResponse(); if (val1 == val2) { displayCorrectResponse(); break; } displayIncorrectResponse(); }
}
public static int readResponse() { Scanner scn = new Scanner(System.in); int val = scn.nextInt(); return val; }
public static int askQuestion(int num1, int num2) {
System.out.println("How much is " + num1 + " times " + num2); return num1 * num2; }
public static boolean isAnswerCorrect(int val1, int val2) {
if (val1 == val2) { return true; } return false; }
public static void displayCorrectResponse() { System.out.println("Very Good"); }
public static void displayIncorrectResponse() { System.out.println("No. Please try again."); }
}
##
Part 2 Modify the program from Part 1 so that various comments are displayed for each answer as follows: Possible responses to a correct answer: Very good! Excellent! Nice work! Keep up the good work! Possible responses to an incorrect answer: No. Please try again. Wrong. Try once more. Don't give up! No. Keep trying
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
