Now i'm stuck on these things:
1) how to call ChooseOperation, DisplayQuestion, CheckAnswer, Display progress from main
2) My do while loop in main is retarded. I cant figure how to do it right...
3) System.println(correct[x-1]}); is wrong.. I want to print out a random array from correct[]
I underlined all the errors that showed in netbeans.
Thanks for the help!
Code:
public class MathTutor {
Scanner input = new Scanner(System.in);
String symbol;
int operation;
int answer;
int correctCounter;
int tryagain = 1;
public static void main (String[] args){
do {
ChooseOperation();
for(int i = 1; i<10; i++){
Random randomGenerator = new Random();
int num1 = randomGenerator.nextInt(10);
int num2 = randomGenerator.nextInt(10);
DisplayQuestion(num1, num2);
CheckAnswer(num1, num2);
}
DisplayProgress();
System.out.println("Enter the number 0 to quit, otherwise press any button to try again.");
tryagain = input.nextInt();
if (tryagain == 0){
System.out.println("Thank you for playing MathTutor");
System.exit(1);
}
else
System.out.println ("New session in progress..");
} while (tryagain != 0);
}
public int ChooseOperation (){
System.out.println("Select an Operation.");
System.out.println("1. Addition");
System.out.println("2. Subtraction");
System.out.println("3. Multiplication");
System.out.println("4. Division");
operation = input.nextInt();
if (operation < 1 || operation > 4)
{
System.out.println("You must enter an apporiate number.");
}
return operation;}
public void DisplayQuestion(int num1, int num2) {
int symbol = operation;
switch(symbol)
{
case 1:
System.out.print("What is " + num1 + " + " + num2 + "? ");
break;
case 2:
System.out.print("What is " + num1 + " - " + num2 + "? ");
break;
case 3:
System.out.print("What is " + num1 + " * " + num2 + "? ");
break;
case 4:
System.out.print("What is " + num1 + " / " + num2 + "? ");
break;
default: System.out.println("Error");
System.exit(1);
answer = input.nextInt();
}}
public void CheckAnswer(int num1, int num2){
String[] correct = {"Very good!","Excellent!","Nice work!","Keep up the good work!"};
String[] incorrect = {"No. Please try again.","Wrong. Try once more.","Don't give up!","No. Keep trying."};
Random randomGenerator = new Random();
int x = randomGenerator.nextInt(4);
int symbol = operation;
switch(symbol)
{
case 1:
if (num1 + num2 == answer){
correctCounter++;
System.println(correct[x-1]});
break;
case 2:
if (num1 - num2 == answer){
correctCounter++;
System.println(correct[x-1]});
break;
case 3:
if (num1 * num2 == answer){
correctCounter++;
System.println(correct[x-1]});
break;
case 4:
if (num1 / num2 == answer){
correctCounter++;
System.println(correct[x-1]});
break;
default: System.println(incorrect[x-1]});
}
public void DisplayProgress() {
double percent = (correctCounter/10) * 10;
if (percent < 75){
System.out.println("Please ask your teacher for extra help with " + operation + ("because you earned ") + percent + "%");
}
else {
System.out.println("You did a great Job! You earned " + percent + "%");
}
}
}

