30.7k views
1 vote
Write a computer-assisted instruction (CAl) Java application that allows the user to pick a type of arithmetic problem to study. An option of 1 means addition problem, 2 means subtraction problem, 3 means multiplication problem, 4 means division problem, 5 means remainder problem, and other means exit. The application will randomly generate two numbers (e.g. 10 and 12) and display the prompts based on the selected option: For 1: How much is the sum of 10 and 12? For 2: How much is 10 minus 12 ? For 3: How much is 10 times 12 ? For 4: How much is 10 divided by 12 ? For 5 : How much is the remainder for 10 divided by 12 ? The user will answer for the question and the program will display the response as follows: If the answer is the first correct answer in the sequence, the application will display "Very good!" If the answer is the second correct answer in the sequence, the application will display "Excellent!" After the second correct answer in the sequence, the application will display "Keep the good work!" for every correct answer. If the answer is incorrect, the application will reset the correct answers counter. If the answer for a question is incorrect: If it is the first attempt, then the application will display "No. Please try again." If it is the second attempt, then the application will display "Wrong. Try once more." If it is the third attempt, then the application will display "Don't give up!" If it is the fourth attempt, then the application will display "No, Keep trying" After the fourth attempt, the application will display "Do you want to try another problem or continue?" If the user exits from the application, the application will display the score of the user in this format: You scored 8 out of 10 in 12 attempts. If the user has answered 8 questions correctly out of 10 questions in 12 attempts.

2 Answers

7 votes

Final answer:

The subject of this question is a Computer-Assisted Instruction (CAI) Java application that allows the user to practice different types of arithmetic problems. The grade level for this question is High School, and the SEO keywords include computer-assisted instruction, Java application, and arithmetic problem.

Step-by-step explanation:

The subject of this question is a Computer-Assisted Instruction (CAI) Java application that allows the user to practice different types of arithmetic problems. The application generates two random numbers and prompts the user with different questions based on the selected option.

The grade level for this question is High School, as it involves basic arithmetic operations such as addition, subtraction, multiplication, division, and remainder.

SEO keywords: computer-assisted instruction, Java application, arithmetic problem, addition, subtraction, multiplication, division, remainder.

User Oleg Pryadko
by
8.1k points
5 votes

Below is the Java code for the computer-assisted instruction (CAI) application.

import java.util.Scanner;

import java.util.Random;

public class CAI {

public static void main(String[] args) {

Scanner input = new Scanner(System.in);

Random random = new Random();

int correctAnswers = 0;

int attempts = 0;

while (true) {

System.out.print("Enter the type of arithmetic problem you want to study (1 for addition, 2 for subtraction, 3 for multiplication, 4 for division, 5 for remainder, or 0 to exit): ");

int choice = input.nextInt();

if (choice == 0) {

break;

}

int num1 = random.nextInt(100);

int num2 = random.nextInt(100);

int correctAnswer = 0;

int attemptsForQuestion = 0;

switch (choice) {

case 1:

correctAnswer = num1 + num2;

System.out.print("How much is " + num1 + " + " + num2 + " ? ");

break;

case 2:

correctAnswer = num1 - num2;

System.out.print("How much is " + num1 + " - " + num2 + " ? ");

break;

case 3:

correctAnswer = num1 * num2;

System.out.print("How much is " + num1 + " x " + num2 + " ? ");

break;

case 4:

if (num2 == 0) {

System.out.println("Error: Cannot divide by zero.");

continue;

}

correctAnswer = num1 / num2;

System.out.print("How much is " + num1 + " / " + num2 + " ? ");

break;

case 5:

if (num2 == 0) {

System.out.println("Error: Cannot divide by zero.");

continue;

}

correctAnswer = num1 % num2;

System.out.print("What is the remainder when " + num1 + " is divided by " + num2 + " ? ");

break;

default:

System.out.println("Invalid choice. Please enter a valid option.");

continue;

}

int userAnswer = input.nextInt();

attemptsForQuestion++;

if (userAnswer == correctAnswer) {

attempts++;

correctAnswers++;

if (correctAnswers == 1) {

System.out.println("Very good!");

} else if (correctAnswers == 2) {

System.out.println("Excellent!");

} else {

System.out.println("Keep up the good work!");

}

} else {

attempts++;

if (attemptsForQuestion == 1) {

System.out.println("No. Please try again.");

} else if (attemptsForQuestion == 2) {

System.out.println("Wrong. Try once more.");

} else if (attemptsForQuestion == 3) {

System.out.println("Don't give up!");

} else if (attemptsForQuestion == 4) {

System.out.println("No, keep trying.");

} else {

System.out.println("Do you want to try another problem or continue? (y/n): ");

char decision = input.next().charAt(0);

if (decision != 'y') {

break;

}

}

}

}

System.out.println("You scored " + correctAnswers + " out of 10 in " + attempts + " attempts.");

}

}

So, the code above is written in Java and uses the Scanner class to handle user input and the Random class to make random numbers. The main loop of the program repeatedly gives the user to select a type of arithmetic problem to study or exit the application.

So, Based on the user's choice, the program makes two random numbers and presents the right arithmetic problem to the user. The user's answer is checked against the correct answer, and feedback is provided accordingly.

User Prabodh Hend
by
7.8k points

No related questions found