Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 6 of 6

Thread: Programming project: random multiplication questions

  1. #1
    Junior Member
    Join Date
    Oct 2013
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Programming project: random multiplication questions

    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[]) {  
    }
    }


  2. #2
    Grand Poobah
    Join Date
    Mar 2011
    Posts
    1,545
    My Mood
    Grumpy
    Thanks
    0
    Thanked 167 Times in 158 Posts

    Default Re: Programming project: random multiplication questions

    Quote Originally Posted by doucettemi View Post
    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).
    That makes no sense to me.
    Improving the world one idiot at a time!

  3. #3
    Junior Member
    Join Date
    Oct 2013
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Programming project: random multiplication questions

    if the user answers correctly, the program randomly picks between four messages. For example it will say "Good Job!" or "Yes, that correct". If they answer incorrectly, it will randomly pick between another set of four messages. For example it will say "Wrong answer" or "No, try again".

  4. #4
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    5,517
    My Mood
    Mellow
    Thanks
    215
    Thanked 698 Times in 680 Posts

    Default Re: Programming project: random multiplication questions

    By Java's naming convention, class names should begin with capital letters. If your instructor suggested the names you've mentioned, use the corrected names.

    Your descriptions of each class' function have been mixed together with what "the program" is supposed to do, so it's unclear to me exactly what each class is supposed to do, what main()'s requirements would then be, or if it really matters. Somewhat guessing, I would say that main() presents a clean sheet of paper to each "Student" using the program. The class that contains main() presents a menu to start a new session or to exit. If a new session is selected, the user's name is collected and an instance of StudentStatistics is created using the name. Then an instance of QuestionGenerator is created with the new instance of StudentStatistics as a parameter. Creating the instance of QuestionGenerator either starts the question/answer session, or main() then calls a method on the QuestionGenerator instance that starts the question/answer portion.

    There are other bells and whistles that occur to me, but what I've described is how I'd start out. My design might change as the pieces are created according to the specific directions given and then are assembled into a functioning program, but that's always part of the process.

  5. #5
    Junior Member
    Join Date
    Oct 2013
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Programming project: random multiplication questions

    I've fixed the class names. To clarify, I have three classes. One is main. The second is the QuestionGenerator class. It controls the questions and the answers. The other class, StudentStatistics, keeps track of the statistics which are the correct percentage and the number of questions answered correctly on the first try.

  6. #6
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    5,517
    My Mood
    Mellow
    Thanks
    215
    Thanked 698 Times in 680 Posts

    Default Re: Programming project: random multiplication questions

    So do you still need help? Any luck with the class that contains the main() method and the main() method itself? Not sure where you are now or if you still have questions. If so, please ask specific questions and/or describe what you don't understand or know how to do.

Similar Threads

  1. Default constructor generating random questions
    By sunny9372 in forum What's Wrong With My Code?
    Replies: 15
    Last Post: April 12th, 2013, 09:51 PM
  2. Default constructor generating random questions
    By sunny9372 in forum What's Wrong With My Code?
    Replies: 0
    Last Post: April 12th, 2013, 07:43 PM
  3. Some legal questions about programming (intellectual property)
    By clydefrog in forum Totally Off Topic
    Replies: 13
    Last Post: April 6th, 2012, 11:08 AM
  4. Best IDE for java programming?(and more questions)
    By Hamed in forum Java Theory & Questions
    Replies: 6
    Last Post: February 13th, 2012, 12:28 AM
  5. [SOLVED] Java- Non repeating random questions.
    By arkaneraven in forum Java Theory & Questions
    Replies: 4
    Last Post: June 15th, 2011, 09:55 AM