Go4Expert

Go4Expert (http://www.go4expert.com/)
-   Java (http://www.go4expert.com/forums/java/)
-   -   MathTutor Program Help (http://www.go4expert.com/forums/mathtutor-program-help-t24068/)

Vanna Guo 3Dec2010 09:31

MathTutor Program Help
 
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 {
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 + "%");
    }     
}
}


virxen 3Dec2010 13:40

Re: MathTutor Program Help
 
send your project in netbeans in a zip file here to help you

Vanna Guo 5Dec2010 03:28

Re: MathTutor Program Help
 
Thanks but I figured it out, my a tutor helped me out. glad to know this forum is happy to help though :)


All times are GMT +5.5. The time now is 11:45.