[go: up one dir, main page]

0% found this document useful (0 votes)
29 views4 pages

IT Project

This version of an arithmetic practice program offers three difficulty levels (easy, medium, hard) that vary the ranges of random operands generated. It includes four arithmetic operations (addition, subtraction, multiplication, division) and tracks a user's progress by keeping score of correct answers. At the end, it displays the user's final score and percentage correct.

Uploaded by

Boithabo
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
29 views4 pages

IT Project

This version of an arithmetic practice program offers three difficulty levels (easy, medium, hard) that vary the ranges of random operands generated. It includes four arithmetic operations (addition, subtraction, multiplication, division) and tracks a user's progress by keeping score of correct answers. At the end, it displays the user's final score and percentage correct.

Uploaded by

Boithabo
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

Creating a more complex and user-friendly arithmetic practice program involves adding features like

different levels of difficulty, tracking user progress, and providing options for customisation. Here's a
more advanced version of the program.

public class AdvancedArithmeticPractice {


public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
Random random = new Random();

int numQuestions = 10;


int correctAnswers = 0;

System.out.println("Welcome to Advanced Arithmetic Practice!");

System.out.print("Enter your name: ");


String userName = scanner.nextLine();

System.out.println("Hi, " + userName + "! Let's get started.");


System.out.println("Choose a difficulty level:");
System.out.println("1. Easy");
System.out.println("2. Medium");
System.out.println("3. Hard");
int difficulty = scanner.nextInt();

int minRange = 1;
int maxRange = 100;

if (difficulty == 2) {
minRange = 50;
maxRange = 200;
} else if (difficulty == 3) {
minRange = 100;
maxRange = 500;
}

for (int i = 1; i <= numQuestions; i++) {


int operand1 = random.nextInt(maxRange - minRange + 1) + minRange;
int operand2 = random.nextInt(maxRange - minRange + 1) + minRange;

int operator = random.nextInt(4); // 0: +, 1: -, 2: *, 3: /


int correctResult = 0;

switch (operator) {
case 0:
correctResult = operand1 + operand2;
System.out.print("Question " + i + ": " + operand1 + " + " + operand2 + " = ");
break;
case 1:
if (operand1 < operand2) {
int temp = operand1;
operand1 = operand2;
operand2 = temp;
}
correctResult = operand1 - operand2;
System.out.print("Question " + i + ": " + operand1 + " - " + operand2 + " = ");
break;
case 2:
operand1 = random.nextInt(20); // Keep multiplication simpler
operand2 = random.nextInt(10);
correctResult = operand1 * operand2;
System.out.print("Question " + i + ": " + operand1 + " * " + operand2 + " = ");
break;
case 3:
operand2 = random.nextInt(10) + 1; // Avoid division by zero
operand1 = operand2 * random.nextInt(10); // Ensure whole number division
correctResult = operand1 / operand2;
System.out.print("Question " + i + ": " + operand1 + " / " + operand2 + " = ");
break;
}

int userAnswer = scanner.nextInt();

if (userAnswer == correctResult) {
System.out.println("Correct!\n");
correctAnswers++;
} else {
System.out.println("Incorrect. The correct answer is " + correctResult + "\n");
}
}

System.out.println("Practice session completed, " + userName + "!");


System.out.println("You answered " + correctAnswers + " out of " + numQuestions + " questions
correctly.");

scanner.close();
}
}
```

This version of the program offers three difficulty levels, each with varying ranges for the operands. It
also includes different types of arithmetic operations: addition, subtraction, multiplication, and
division. Users can choose their difficulty level and receive feedback on their performance at the
end.import java.util.Random;
import java.util.Scanner;

public class AdvancedArithmeticPractice {


public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
Random random = new Random();

int numQuestions = 10;


int correctAnswers = 0;
System.out.println("Welcome to Advanced Arithmetic Practice!");

System.out.print("Enter your name: ");


String userName = scanner.nextLine();

System.out.println("Hi, " + userName + "! Let's get started.");


System.out.println("Choose a difficulty level:");
System.out.println("1. Easy");
System.out.println("2. Medium");
System.out.println("3. Hard");
int difficulty = scanner.nextInt();

int minRange = 1;
int maxRange = 100;

if (difficulty == 2) {
minRange = 50;
maxRange = 200;
} else if (difficulty == 3) {
minRange = 100;
maxRange = 500;
}

for (int i = 1; i <= numQuestions; i++) {


int operand1 = random.nextInt(maxRange - minRange + 1) + minRange;
int operand2 = random.nextInt(maxRange - minRange + 1) + minRange;

int operator = random.nextInt(4); // 0: +, 1: -, 2: *, 3: /


int correctResult = 0;

switch (operator) {
case 0:
correctResult = operand1 + operand2;
System.out.print("Question " + i + ": " + operand1 + " + " + operand2 + " = ");
break;
case 1:
if (operand1 < operand2) {
int temp = operand1;
operand1 = operand2;
operand2 = temp;
}
correctResult = operand1 - operand2;
System.out.print("Question " + i + ": " + operand1 + " - " + operand2 + " = ");
break;
case 2:
operand1 = random.nextInt(20); // Keep multiplication simpler
operand2 = random.nextInt(10);
correctResult = operand1 * operand2;
System.out.print("Question " + i + ": " + operand1 + " * " + operand2 + " = ");
break;
case 3:
operand2 = random.nextInt(10) + 1; // Avoid division by zero
operand1 = operand2 * random.nextInt(10); // Ensure whole number division
correctResult = operand1 / operand2;
System.out.print("Question " + i + ": " + operand1 + " / " + operand2 + " = ");
break;
}

int userAnswer = scanner.nextInt();

if (userAnswer == correctResult) {
System.out.println("Correct!\n");
correctAnswers++;
} else {
System.out.println("Incorrect. The correct answer is " + correctResult + "\n");
}
}

System.out.println("Practice session completed, " + userName + "!");


System.out.println("You answered " + correctAnswers + " out of " + numQuestions + " questions
correctly.");

scanner.close();
}
}

You might also like