Welcome to Westonci.ca, your one-stop destination for finding answers to all your questions. Join our expert community now! Join our Q&A platform to get precise answers from experts in diverse fields and enhance your understanding. Join our platform to connect with experts ready to provide precise answers to your questions in different areas.
Sagot :
Answer:
Explanation:
The following program is written in Java and creates three levels with the different set of randomly generated arithmetic problems. As the player goes getting more points they advance every 5 points to the next level.
import java.util.Random;
import java.util.Scanner;
class Main {
private static Random random = new Random();
private static Scanner in = new Scanner(System.in);
static int points = 0;
public static void main(String[] args) {
while (true) {
System.out.println(points);
if (points < 5) {
System.out.println("Starting Level 1");
levelOne();
} else if (points < 10) {
System.out.println("Starting Level 2");
levelTwo();
} else if (points < 15) {
System.out.println("Starting Level 3");
levelThree();
}
}
}
public static boolean levelOne() {
int numberOne = random.nextInt(10);
int numberTwo = random.nextInt((10 - numberOne));
int answer = numberOne + numberTwo;
int count = 0;
while (points < 5 && count < 2) {
System.out.println("What is " + numberOne + " + " + numberTwo + "?: ");
int userChoice = in.nextInt();
if (userChoice == answer) {
points += 1;
levelOne();
} else {
count += 1;
}
}
return false;
}
public static boolean levelTwo() {
int numberOne = random.nextInt(10);
int numberTwo = random.nextInt(10);
int answer = numberOne + numberTwo;
int count = 0;
while (points < 10 && count < 2) {
System.out.println("What is " + numberOne + " + " + numberTwo + "?: ");
int userChoice = in.nextInt();
if (userChoice == answer) {
points += 1;
levelTwo();
} else {
count += 1;
}
}
return false;
}
public static boolean levelThree() {
int numberOne = random.nextInt(10);
int numberTwo = random.nextInt(10);
int answer = numberOne - numberTwo;
int count = 0;
if (answer <= 0) {
levelThree();
}
while (points < 15 && count < 2) {
System.out.println("What is " + numberOne + " - " + numberTwo + "?: ");
int userChoice = in.nextInt();
if (userChoice == answer) {
points += 1;
levelThree();
} else {
count += 1;
}
}
return false;
}
}
We hope you found this helpful. Feel free to come back anytime for more accurate answers and updated information. We hope you found what you were looking for. Feel free to revisit us for more answers and updated information. Westonci.ca is your trusted source for answers. Visit us again to find more information on diverse topics.