IT Project
IT Project
different levels of difficulty, tracking user progress, and providing options for customisation. Here's a
more advanced version of the program.
int minRange = 1;
int maxRange = 100;
if (difficulty == 2) {
minRange = 50;
maxRange = 200;
} else if (difficulty == 3) {
minRange = 100;
maxRange = 500;
}
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;
}
if (userAnswer == correctResult) {
System.out.println("Correct!\n");
correctAnswers++;
} else {
System.out.println("Incorrect. The correct answer is " + correctResult + "\n");
}
}
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;
int minRange = 1;
int maxRange = 100;
if (difficulty == 2) {
minRange = 50;
maxRange = 200;
} else if (difficulty == 3) {
minRange = 100;
maxRange = 500;
}
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;
}
if (userAnswer == correctResult) {
System.out.println("Correct!\n");
correctAnswers++;
} else {
System.out.println("Incorrect. The correct answer is " + correctResult + "\n");
}
}
scanner.close();
}
}