Question
Please help with java code. Code from ## part 4 ## 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 4 ## listed below:
import java.security.SecureRandom; import java.util.Scanner;
public class Test { public static void main(String[] args) { Scanner sc = new Scanner(System.in); String flag; do { //calling quiz quiz(sc); //getting user input about next round System.out.print(" Do you want another round?(yeso): "); flag = sc.next(); System.out.println(); }while(flag.equalsIgnoreCase("yes")); sc.close(); }
public static void quiz(Scanner sc) { SecureRandom rand = new SecureRandom();
int countCorrect = 0;//for count correct answer
for (int i = 1; i
askquestion(first, second, i);
int response = readResponse(sc);
if (isAnswerCorrect(correctAns, response)) { displayCorrectResponse(rand); countCorrect++; } else displayIncorrectResponse(rand); } displayCompletionMessage(countCorrect); }
private static void displayCompletionMessage(int countCorrect) { double percent = ((double) countCorrect / 10.0) * 100.0; System.out.println(" You Scored: " + percent + "%"); if (percent
private static void displayIncorrectResponse(SecureRandom rand) { String incorrect[] = { "No. Please try again", "Wrong. Try once more", "Don't give up!", "No. Keep trying" };
// generating random index int index = rand.nextInt(incorrect.length);
System.out.println(incorrect[index]); }
private static void displayCorrectResponse(SecureRandom rand) { String appreciate[] = { "Very good!", "Excellent", "Nice work!", "Keep up the good work!" };
// generating random index int index = rand.nextInt(appreciate.length);
System.out.println(appreciate[index]); }
private static boolean isAnswerCorrect(int correctAns, int response) { return correctAns == response; }
private static int readResponse(Scanner sc) { System.out.print("Ans. "); int response = sc.nextInt(); return response; }
private static void askquestion(int first, int second, int i) { System.out.println("Q."+i+" how much is " + first + " times " + second + "?"); } }
##Part 3 sample output##
**Should follow**
name: "CAI5.java"
Problem 1 (CAI5.java): The program shall generate random numbers with a SecureRandom object
Problem 1 (CAI5.java): The program shall ask the student to enter a difficulty level of 1, 2, 3, or 4
Problem 1 (CAI5.java): A difficulty level of 1 shall limit random numbers to the range of 0-9, inclusive
Problem 1 (CAI5.java): A difficulty level of 2 shall limit random numbers to the range of 0-99, inclusive
Problem 1 (CAI5.java): A difficulty level of 3 shall limit random numbers to the range of 0-999, inclusive
Problem 1 (CAI5.java): A difficulty level of 4 shall limit random numbers to the range of 0-9999, inclusive
Problem 1 (CAI5.java): The program shall ask the student to enter a problem type of 1, 2, 3, 4, or 5 with an appropriate human-readable label
Problem 1 (CAI5.java): The program shall ask the student to solve 10 different problems, as determined by the problem type
Problem 1 (CAI5.java): A problem type of 1 shall limit the program to generating only addition problems
Problem 1 (CAI5.java): A problem type of 2 shall limit the program to generating only multiplication problems
Problem 1 (CAI5.java): A problem type of 3 shall limit the program to generating only subtraction problems
Problem 1 (CAI5.java): A problem type of 4 shall limit the program to generating only division problems
Problem 1 (CAI5.java): A problem type of 5 shall result questions that are a randomly mixture of addition, multiplication, subtraction, and division problems
Problem 1 (CAI5.java): Problems shall contain two numbers sampled from a uniform random distribution with bounds determined by the problem difficulty
Problem 1 (CAI5.java): The program shall display a random positive message if the student provides a correct response
Problem 1 (CAI5.java): The program shall display a random negative message if the student provides an incorrect response
Problem 1 (CAI5.java): The program shall display the student's score after the student has attempted to solve 10 problems
Problem 1 (CAI5.java): The student's score shall be the percentage of problems correctly solved
Problem 1 (CAI5.java): The program shall display the message "Please ask your teacher for extra help." if the student's score is less than 75%
Problem 1 (CAI5.java): 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%
Problem 1 (CAI5.java): The program shall ask the student if they want to solve a new problem set after the score message has been displayed
Problem 1 (CAI5.java): The program shall restart when the student agrees to solve a new problem set
Problem 1 (CAI5.java): The program shall terminate when the student declines to solve another problem set
Problem 1 (CAI5.java): Create a method called "quiz" that contains the program logic
Problem 1 (CAI5.java): Create a method called "readDifficulty" that reads the difficulty level from the student
Problem 1 (CAI5.java): Create a method called "readProblemType" that reads the difficulty level from the student
Problem 1 (CAI5.java): Create a method called "generateQuestionArgument" that uses the difficulty level to generate a random number
Problem 1 (CAI5.java): Create a method called "askQuestion" that prints the problem to the screen
Problem 1 (CAI5.java): Create a method called "readResponse" that reads the answer from the student
Problem 1 (CAI5.java): Create a method called "isAsnwerCorrect" that checks to see if the student's answer matches the correct answer to the problem
Problem 1 (CAI5.java): Create a method called "displayCorrectResponse" that prints out the response when a student enters a correct answer
Problem 1 (CAI5.java): Create a method called "displayInorrectResponse" that prints out the response when a student enters an incorrect answer
Problem 1 (CAI5.java): Create a method called "displayCompletionMessage" that prints out the studen't score and appropriate score response
Problem 1 (CAI5.java): Create a main method that runs your program by calling the "quiz" method
Part 5 Modify the program from Part 4 to allow the user to pick a type of arithmetic problem to study. An option of 1 means addition problems only, 2 means multiplication problems only, 3 means subtraction problems only, 4 means division problems only and 5 means a random mixture of all these types. Requirements The program shall generate random numbers with a Secure Random object The program shall ask the student to enter a difficulty level of 1, 2, 3, or 4 A difficulty level of 1 shall limit random numbers to the range of 0-9, inclusive A difficulty level of 2 shall limit random numbers to the range of 0-99, inclusive A difficulty level of 3 shall limit random numbers to the range of 0-999, inclusive A difficulty level of 4 shall limit random numbers to the range of 0-9999, inclusive The program shall ask the student to enter a problem type of 1, 2, 3, 4, or 5 with an appropriate human-readable label The program shall ask the student to solve 10 different problems, as determined by the problem type A problem type of 1 shall limit the program to generating only addition problems A problem type of 2 shall limit the program to generating only multiplication problems A problem type of 3 shall limit the program to generating only subtraction problems A problem type of 4 shall limit the program to generating only division problems A problem type of 5 shall result questions that are a randomly mixture of addition, multiplication, subtraction, and division problems Problems shall contain two numbers sampled from a uniform random distribution with bounds determined by the problem difficulty 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 method called "read Difficulty" that reads the difficulty level from the student Create a method called "readProblem Type" that reads the difficulty level from the student Create a method called "generate QuestionArgument" that uses the difficulty level to generate a random number Create a method called "ask Question" that prints the problem to the screen Create a method called "read Response" that reads the answer from the student Create a method called "isAsnwerCorrect" that checks to see if the student's answer matches the correct answer to the problem Create a method called "displayCorrectResponse" that prints out the response when a student enters a correct answer Create a method called "displaylnorrectResponse" that prints out the response when a student enters an incorrect answer Create a method called "displayCompletion Message" that prints out the studen't score and appropriate score response Create a main method that runs your program by calling the "quiz" method VCI y svuu: Q.3 how much is 7 times 6? Ans. 42 Keep up the good work! 0.4 how much is 1 times 8? Ans. 8 Keep up the good work! Q.5 how much is 4 times 3? Ans. 12 Excellecnt 0.6 how much is 4 times 7? Ans. 28 Nice work! 0.7 how much is 1 times 6? Ans. 6 Excellecnt 0.8 how much is 3 times 12 Ans. 3 Excellecnt Q.9 how much is 5 times 7? Ans. 35 Excellecnt Q.10 how much is 6 times 7? Ans. 42 Excellecht You Scored: 100.0% Congratulations, you are ready to go to next level! Do you want another round? (yeso): yes 0.1 how much is 4 times 6? Ans. 24 Very good! Q.2 how much is 7 times 7? Ans. 48 No. Please try again Q.3 how much is 9 times 7? AnsStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access with AI-Powered 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