I am trying to get my program to run through different difficulties by using if statements, but I'm coming across a few errors. I am also having issues with my public static int[]
. I was trying to find a way to get rid of it completely and have each array be set in its own if statement.
import java.util.*;
class CAI {
public static void main (String[] arguments) {
menu();//calls menu method
compute();//calls compute method
}
public static void menu() {//method that displays menu
System.out.println (" CAI MENU " );
System.out.println ("\n1) DIFFICULTY 1\n2) DIFFICULTY 2\n3) DIFFICULTY 3\n4) DIFFICULTY 4\n5)DIFFICULTY 5");
}
public static int[] Blop(){
Random rand = new Random();
int arr[] = new int[4];
arr[0] = rand.nextInt(9);
arr[1] = rand.nextInt(9);
arr[3] = rand.nextInt(99);
arr[4] = rand.nextInt(99);
return arr;
}
public static void compute(){
int option;
Scanner input = new Scanner(System.in);
System.out.println("Enter an option: ");
option = input.nextInt();
while (option != 0){
if(option == 1){
int num[] = new int[2];
int ans;
String choice;
do{
num = Blop();
do{
System.out.print("How much is " + num[0] + " times " + num[1] + " ? :");
ans = input.nextInt();
String Correct;
String Wrong;
String[] correct = {"Very good! ","Excellent! ","Nice work! ","Keep up the good work! "};
String[] wrong = {"No. Please try again. ","Wrong. Try once more. ","Don’t give up! ","No. Keep trying "};
Random rand = new Random();
Correct = correct[rand.nextInt(correct.length)];
Wrong = wrong[rand.nextInt(wrong.length)];
if(ans == (num[0]*num[1])){
System.out.print(Correct);
}else{
System.out.print(Wrong);
}
}while(ans != (num[0]*num[1]));
System.out.print("Do you want more questions(yes/no) :");
input.nextLine();
choice = input.nextLine();
}while(choice.equalsIgnoreCase("yes"));
}
if(option == 2){
int num[] = new int[2];
int ans;
String choice;
do{
num = Blop();
do{
System.out.print("How much is " + num[2] + " times " + num[3] + " ? :");
ans = input.nextInt();
String Correct;
String Wrong;
String[] correct = {"Very good! ","Excellent! ","Nice work! ","Keep up the good work! "};
String[] wrong = {"No. Please try again. ","Wrong. Try once more. ","Don’t give up! ","No. Keep trying "};
Random rand = new Random();
Correct = correct[rand.nextInt(correct.length)];
Wrong = wrong[rand.nextInt(wrong.length)];
if(ans == (num[2]*num[3])){
System.out.print(Correct);
}else{
System.out.print(Wrong);
}
}while(ans != (num[2]*num[3]));
System.out.print("Do you want more questions(yes/no) :");
input.nextLine();
choice = input.nextLine();
}while(choice.equalsIgnoreCase("yes"));
}
}
}
}
Aucun commentaire:
Enregistrer un commentaire