Hi all,
I've been working on this program for my object oriented programming class and I'm having a bit of trouble. We have to make a program that continuously produces pairs of random numbers for multiplication questions and asks the user to input their product. If the user puts in a correct answer, it is supposed to respond with one of four random answers (four for correct answers and four for incorrect answers). Once the user has entered 10 correct answers, the program is supposed to start showing the correct percentage and the number of questions answered correctly on the first try. I'm supposed to have three classes. One is called questionGenerator and it controls the questions and answers. The second is called studentStatistics and it keeps track of the correct percentage and the number of correct answers on the first try. The third is the main class called project2. The program is controlled through a flag controlled loop and if the user enters -1, the program should display the stats and exit. Now since I am new to Java, this seems like a mountain to me and I'm having lots of trouble. I have my questionGenerator and studentStatistcs classes done (I think) and I'm unsure of what to do in main. My code is pasted below. Any help is appreciated.
questionGenerator
public class questionGenerator { private questionGenerator() { Random randomNumbers = new Random(); int answer; // the correct answer. // get two random numbers between 1 and 20. int digit1 = randomNumbers.nextInt(20); int digit2 = randomNumbers.nextInt(20); answer = digit1 * digit2; System.out.printf("How much is %d times %d?\n", digit1, digit2); // ask the user to answer question. Scanner input = new Scanner(System.in); int studentGuess; // the user's guess. do { System.out.println("Enter your answer (-1 to exit):"); studentGuess = input.nextInt(); } while (studentGuess != -1); // end do while. } } // end method questionGenerator.
studentStatistics
public class studentStatistics { int studentGuess; // User's input. int answer; // correct answer. int correctMessage; // Random correct message. int incorrectMessage; // Random incorrect message. int incorrectCount = 0; // Number of incorrect answers. int correctCount = 0; // Number of correct answers. private studentStatistics(){ if (studentGuess != answer) { switch (incorrectMessage) { case 1: System.out.println("No, Please try again."); incorrectCount++; break; case 2: System.out.println("Wrong. Try once more."); incorrectCount++; break; case 3: System.out.println("Don't give up!"); incorrectCount++; break; case 4: System.out.println("No. Keep trying."); incorrectCount++; break; } } else { switch (correctMessage) { case 1: System.out.println("Very Good!"); correctCount++; break; case 2: System.out.println("Excellent!"); correctCount++; break; case 3: System.out.println("Nice Work!"); correctCount++; break; case 4: System.out.println("Keep up the good work!"); correctCount++; break; } } } }
main (project2)
public class project2 { public static void main(String args[]) { } }