Question
Please help with java code. Code from ## part 2 ## listed below: import java.security.SecureRandom; import java.util.Scanner; public class Test { public static void main(String[]
Please help with java code. Code from ## part 2 ## listed below:
import java.security.SecureRandom; import java.util.Scanner; public class Test { public static void main(String[] args) { /*Create an array of responses * for correct answers */ String appreciate[]= { "Very good!","Excellecnt","Nice work!", "Keep up the good work!" }; /*Create an array of responses * for incorrect answers */ String incorrect[]= { "No. Please try again", "Wrong. Try once more", "Don't give up!", "No. Keep trying" }; int r;//declare a random variable,r
Scanner sc = new Scanner(System.in); // declare SecureRandom object SecureRandom rand = new SecureRandom();
// generate two signle digit random numbers int first = rand.nextInt(10); int second = rand.nextInt(10); // show the question int ans = first * second; System.out.println("how much is " + first + " times " + second + "? "); // start a infinite loop while (true) {
// ask user for input System.out.print("Ans. "); int user = sc.nextInt();
// check answer if (user == ans) { // show congratulate user for right answer System.out.println(); /* * Generate a random number * in a range of 0 to 4(exclusive) * and then print the value from appreciate * array at location r * */ r=(int)(rand.nextInt(3)); System.out.println(appreciate[r]); break; }
// ask another another answer when first answer is wrong System.out.println(); /* * Generate a random number * in a range of 0 to 4(exclusive) * and then print the value from incorrect * array at location r * */ r=(int)(rand.nextInt(3)); System.out.println(incorrect[r]); System.out.println(); } sc.close(); } } //end of the class
##Part 2 sample output##
Part 3 Modify the program from Part 2 to use your question generation method to ask the student 10 different questions. Give students only one chance at answering each question. Count the number of correct and incorrect responses typed by the student. After the program has asked 10 questions (and the student types 10 answers), your program should calculate the percentage that are correct. If the percentage is lower than 75%, display "Please ask your teacher for extra help.", then reset the program so another student can try it. If the percentage is 75% or higher, display "Congratulations, you are ready to go to the next level!", then reset the program so another student can try it. Requirements The program shall generate random numbers with a SecureRandom object The program shall ask the student to solve 10 different multiplication problems Multiplication problems shall contain two numbers sampled from a uniform random distribution in the range of O 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 display the student's score after the student has attempted to solve 10 problems The student's score shall be the percentage of problems correctly solved The program shall display the message "Please ask your teacher for extra help." if the student's score is less than 75% The program shall display the message "Congratulations, you are ready to go to the next level!" if the student's score is greater than or equal to 75% The program shall ask the student if they want to solve a new problem set after the score message has been displayed The program shall restart when the student agrees to solve a new problem set The program shall terminate when the student declines to solve another problem set 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 "isAsnwerCorrect" 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 "displayinorrectResponse" that prints out the response when a student enters an incorrect answer Create a function called "display Completion Message" that prints out the student score and appropriate score response Create a main method that runs your program by calling the "quiz" method how much is 9 times 7? Ans. 5 No. Please try again Ans. 3 No. Please try again Ans. 63 Nice workStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started