Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I need help with my code. Here is the assignment: I am having the following problems with my code: 1. The option to have a

I need help with my code. Here is the assignment:
image text in transcribed
I am having the following problems with my code:
1. The option to have a random mix of problems doesnt work correctly. Every single problem has to be randomized, not the whole set of 10 problems.
2. My method to generate score doesnt work correctly if the student does not make 100%.
3. When a student finally gets a question right after answering it incorrectly, it does not display the right response to them nor does it increment the variable for right answers.
4. The option to restart the program after a student completes it does not work properly.
Can you please help me? Here is my code:
/*********************************************************************************************************************************
* Filename: Arithmetic.java
* Description: Allows students to study different types of Arithmetic
* Programmer: Kenneth Holder
* Date: 10/23/2018
********************************************************************************************************************************/
import java.util.Random;
import java.util.Scanner;
public class Arithmetic {
private int operation, rightResponse, wrongResponse, rightAnswer = 0, wrongAnswer = 0;
public void menu() {
// display message to introduce arithmetic problems
System.out.println("Welcome to Arithmetic Problem Solving");
System.out.println("Type 1 for addition problems, 2 for subtraction problems, 3 for multiplication problems, 4 for division problems, and 5 for random");
System.out.println("To exit, type -1");
Scanner input = new Scanner(System.in);
System.out.println("Make Selection: ");
operation = input.nextInt();
}
public void generateQuestion() {
Scanner input = new Scanner(System.in);
Random randomNumber = new Random();
int answer, userAnswer, x, y, count = 0;
while (operation != -1) {
if (operation == 1) {
while (count
count++;
x = randomNumber.nextInt(9);
y = randomNumber.nextInt(9);
System.out.println("What is " + x + " plus " + y + "?");
answer = x + y;
userAnswer = input.nextInt();
if (userAnswer == answer) {
rightResponse = randomNumber.nextInt(4);
while (rightResponse == 0) {
rightResponse = randomNumber.nextInt(4);
}
if (rightResponse == 1) {
System.out.println("Very good!");
}
else if (rightResponse == 2) {
System.out.println("Excellent!");
}
else if (rightResponse == 3) {
System.out.println("Nice work!");
}
else if (rightResponse == 4) {
System.out.println("Keep up the good work!");
}
rightAnswer++;
operation = 1;
}
while (userAnswer != answer) {
count++;
wrongResponse = randomNumber.nextInt(3);
while (wrongResponse == 0) {
wrongResponse = randomNumber.nextInt(3);
}
if (wrongResponse == 1) {
System.out.println("No. Please try again. Wrong.");
}
else if (wrongResponse == 2) {
System.out.println("Try once more. Don't give up!");
}
else if (wrongResponse == 3) {
System.out.println("No. Keep trying.");
}
wrongAnswer++;
System.out.println("What is " + x + " plus " + y + "?");
userAnswer = input.nextInt();
}
}
}
else if (operation == 2) {
while (count
count++;
x = randomNumber.nextInt(9);
y = randomNumber.nextInt(9);
System.out.println("What is " + x + " minus " + y + "?");
answer = x - y;
userAnswer = input.nextInt();
if (userAnswer == answer) {
rightResponse = randomNumber.nextInt(4);
while (rightResponse == 0) {
rightResponse = randomNumber.nextInt(4);
}
if (rightResponse == 1) {
System.out.println("Very good!");
}
else if (rightResponse == 2) {
System.out.println("Excellent!");
}
else if (rightResponse == 3) {
System.out.println("Nice work!");
}
else if (rightResponse == 4) {
System.out.println("Keep up the good work!");
}
rightAnswer++;
operation = 2;
}
while (userAnswer != answer) {
count++;
wrongResponse = randomNumber.nextInt(3);
while (wrongResponse == 0) {
wrongResponse = randomNumber.nextInt(3);
}
if (wrongResponse == 1) {
System.out.println("No. Please try again. Wrong.");
}
else if (wrongResponse == 2) {
System.out.println("Try once more. Don't give up!");
}
else if (wrongResponse == 3) {
System.out.println("No. Keep trying.");
}
wrongAnswer++;
System.out.println("What is " + x + " minus " + y + "?");
userAnswer = input.nextInt();
}
}
}
else if (operation == 3) {
while (count
count++;
x = randomNumber.nextInt(9);
y = randomNumber.nextInt(9);
System.out.println("What is " + x + " times " + y + "?");
answer = x * y;
userAnswer = input.nextInt();
if (userAnswer == answer) {
rightResponse = randomNumber.nextInt(4);
while (rightResponse == 0) {
rightResponse = randomNumber.nextInt(4);
}
if (rightResponse == 1) {
System.out.println("Very good!");
}
else if (rightResponse == 2) {
System.out.println("Excellent!");
}
else if (rightResponse == 3) {
System.out.println("Nice work!");
}
else if (rightResponse == 4) {
System.out.println("Keep up the good work!");
}
rightAnswer++;
operation = 3;
}
while (userAnswer != answer) {
count++;
wrongResponse = randomNumber.nextInt(3);
while (wrongResponse == 0) {
wrongResponse = randomNumber.nextInt(3);
}
if (wrongResponse == 1) {
System.out.println("No. Please try again. Wrong.");
}
else if (wrongResponse == 2) {
System.out.println("Try once more. Don't give up!");
}
else if (wrongResponse == 3) {
System.out.println("No. Keep trying.");
}
wrongAnswer++;
System.out.println("What is " + x + " times " + y + "?");
userAnswer = input.nextInt();
}
}
}
else if (operation == 4) {
while (count
count++;
x = randomNumber.nextInt(9);
y = randomNumber.nextInt(9);
while (y == 0) {
y = randomNumber.nextInt(9);
}
System.out.println("What is " + x + " divided by " + y + "?");
answer = x / y;
userAnswer = input.nextInt();
if (userAnswer == answer) {
rightResponse = randomNumber.nextInt(4);
while (rightResponse == 0) {
rightResponse = randomNumber.nextInt(4);
}
if (rightResponse == 1) {
System.out.println("Very good!");
}
else if (rightResponse == 2) {
System.out.println("Excellent!");
}
else if (rightResponse == 3) {
System.out.println("Nice work!");
}
else if (rightResponse == 4) {
System.out.println("Keep up the good work!");
}
rightAnswer++;
operation = 4;
}
while (userAnswer != answer) {
count++;
wrongResponse = randomNumber.nextInt(3);
while (wrongResponse == 0) {
wrongResponse = randomNumber.nextInt(3);
}
if (wrongResponse == 1) {
System.out.println("No. Please try again. Wrong.");
}
else if (wrongResponse == 2) {
System.out.println("Try once more. Don't give up!");
}
else if (wrongResponse == 3) {
System.out.println("No. Keep trying.");
}
wrongAnswer++;
System.out.println("What is " + x + " divided by " + y + "?");
userAnswer = input.nextInt();
}
}
}
else if (operation == 5) {
randomOperation();
}
else {
System.out.println("Invalid entry, try again");
operation = input.nextInt();
}
if (count >= 10) {
generateScore();
}
}
}
public void randomOperation() {
Random rand = new Random();
operation = rand.nextInt(3)+1;
generateQuestion();
}
public void generateScore() {
Scanner input = new Scanner(System.in);
double score = (rightAnswer/10)*100;
System.out.println("Correct answers: " + rightAnswer);
System.out.println("Incorrect answers: " + wrongAnswer);
System.out.println("Score: " + score + " %");
if (score
System.out.println("Please ask your teacher for extra help");
}
else if (score >= 75) {
System.out.println("Congratulations, you are ready to go to the next level!");
}
System.out.println("Do you want to try again? 1 for yes and 2 for no");
int answer = input.nextInt();
if (answer == 1) {
rightAnswer = 0;
wrongAnswer = 0;
menu();
}
else if (answer == 2) {
System.exit(0);
}
else {
System.out.println("Invalid entry, try again.");
answer = input.nextInt();
}
}
}
public class ArithmeticTest {
public static void main(String[] args) {
Arithmetic ob = new Arithmetic();
ob.menu();
ob.generateQuestion();
}
}
NOTE: To create a random number you must declared the random object ex private Random random Number - new RandomO. Then create the number ex int munnber randomNurnber.nextInt(10). /ht generates a tumba between 0-9 number randomNumber nextint(10) + 1; lfit generates a number between 1-10 Computer-Assisted Iestruction: Part I: Write a program using classes and methods to allow the user to pick a type of arithmetic problem to study. An option of I means addition problems only. 2 means subtraction problems only, 3 means multiplication problems only, 4 means division problems only and 5 means random michure of all these types The use of computers in education is referred to as computer- assisted instruction (CAl), Write a program that will help an elementary school student learn arithmetic operations. Use a Random abject to produce two positive one- digit integers. The program should then prompt the user with a question, such as How much is 6 times 7? The student then inputs the answer. Next, the program checks the student's answer. If it's correct, display the message "Very good" and ask another multiplication question If the answer is wrong, display the message "No. Please try again." and let the student try the same question repeatedly until the student finally gets it right A separate method should be used to generate each new question. This method should be called once when the application begins execution and each time the user answers the question correctly Part 2: (Computer- Assisted Instruction: Reducing Student Fatigue) One problem in CAI environments is student fatigue. This can be reduced by varying the computer's responses to hold the student's attention, 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 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 or if statement to issue the responses. Part 3: (Computer-Assisted Instruction: Monitoring Student Performance) More sophisticated computer- assisted instruction systems monitor the student's performance over a period of time. Count the number of correct and incorrect responses typed by the student. After the student types 10 answers, your program should calculate the percentages 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 Ifthe 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

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

Step: 3

blur-text-image

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