I'm suppose to make a program that allows the user to choose addition, subtraction, multiplication, and division. They then get 10 questions. At the end of the questions the user gets a report on how well or bad they did. 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 { [u]ChooseOperation();[/u] for(int i = 1; i<10; i++){ Random randomGenerator = new Random(); int num1 = randomGenerator.nextInt(10); int num2 = randomGenerator.nextInt(10); [u]DisplayQuestion(num1, num2);[/u] [u]CheckAnswer(num1, num2);[/u] } [u]DisplayProgress();[/u] System.out.println("Enter the number 0 to quit, otherwise press any button to try again."); [u]tryagain = input.nextInt();[/u] if (tryagain == 0){ System.out.println("Thank you for playing MathTutor"); System.exit(1); } else System.out.println ("New session in progress.."); [u]} while (tryagain != 0);[/u] } 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++; [u]System.println(correct[x-1]});[/u] break; case 2: if (num1 - num2 == answer){ correctCounter++; [u]System.println(correct[x-1]});[/u] break; case 3: if (num1 * num2 == answer){ correctCounter++; [u]System.println(correct[x-1]});[/u] break; case 4: if (num1 / num2 == answer){ correctCounter++; [u]System.println(correct[x-1]});[/u] break; default: [u]System.println(incorrect[x-1]});[/u] } 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 + "%"); } } }
Thanks but I figured it out, my a tutor helped me out. glad to know this forum is happy to help though