Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Please help with java code. Code from ## part 3 ## listed below: import java.security.SecureRandom; import java.util.Scanner; public class Test { public static void main(String[]

image text in transcribed

Please help with java code. Code from ## part 3 ## 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##

image text in transcribed

Part 4 Modify the program from Part 3 to allow the user to enter a difficulty level. At a difficulty level of 1, the program should use only single-digit numbers in the problems; at a difficulty level of 2, numbers as large as two digits, and so on. Allow for four levels of difficulty. Requirements The program shall generate random numbers with a SecureRandom 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 solve 10 different multiplication problems Multiplication 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 function called "readDifficulty" that reads the difficulty level from the student Create a function called "generate QuestionArgument" that uses the difficulty level to generate a random number 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 "displaylnorrectResponse" that prints out the response when a student enters an incorrect answer Create a function 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 guuu Q.3 how much is 7 times 6? Ans. 42 Keep up the good work! Q.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 Q.6 how much is 4 times 7? Ans. 28 Nice work! Q.7 how much is 1 times 6? Ans. 6 Excellecnt Q.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 Excellecnt You Scored: 100.0% Congratulations, you are ready to go to next level! Do you want another round? (yeso): yes Q.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? Ans

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions