Question
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
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.
This part modifies part 4, the coding for part 4 is provided 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
int difficulty = readDifficulty(sc); System.out.println();
for (int i = 1; i
int first = generateQuestionArgument(rand, difficulty); int second = generateQuestionArgument(rand, difficulty); int correctAns = first * second;// correct ans
askquestion(first, second, i);
int response = readResponse(sc);
if (isAnswerCorrect(correctAns, response)) { displayCorrectResponse(rand); countCorrect++; } else displayIncorrectResponse(rand); } displayCompletionMessage(countCorrect); }
//generating random number according to given dificulty private static int generateQuestionArgument(SecureRandom rand, int difficulty) { int argument = 0; if (difficulty == 1) argument = rand.nextInt(10); else if (difficulty == 2) argument = rand.nextInt(100); else if (difficulty == 3) argument = rand.nextInt(1000); else argument = rand.nextInt(10000); return argument; }
//reading difficulty from user private static int readDifficulty(Scanner sc) { System.out.print("Enter difficulty level(1-4): "); return sc.nextInt(); }
//calculating percent and displaying completion result 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.err.println(incorrect[index]); //changing the color to red for incorrect response }
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 + "?"); } }
---------------------------------------------------
The program also needs to follow the following ruleset:
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 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 "readDifficulty" that reads the difficulty level from the student
Create a method called "readProblemType" that reads the difficulty level from the student
Create a method called "generateQuestionArgument" that uses the difficulty level to generate a random number
Create a method called "askQuestion" that prints the problem to the screen
Create a method called "readResponse" that reads the answer from the student
Create a method called "isAnswerCorrect" 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 "displayIncorrectResponse" that prints out the response when a student enters an incorrect answer
Create a method called "displayCompletionMessage" that prints out the studen't score and appropriate score response
Create a main method that runs your program by calling the "quiz" method
If you have any questions please leave a comment so I could clarify. Thank you.
Requirements The program shall generale 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 limitacion 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 stall display a randon 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 7596 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 care 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 'reaci Problem Type" that reads the difficulty level from the student Create a method called 'generateQuestionArgument that uses the difficulty level to generate a random number Create a mcthod 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 'IsAnwerCorrect" that checks to see if the student's answer matches the correct answer to the problem . Create a method called "displayCorrectResponse that prints out theresse when a student enters a correct answer Create a method called "displayinorrectResponse" that prints out the response when a student enters an incorrect answer Create a method called "displayCompletion Message that prints out the student score and appropriate score response Create a main method that runs your program by calling the "quiz" method
Step 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