Concepts used: Random number generation, definite loop, counter variable, modular programming using functions (aka methods), string data (very basic), many-way decision making.

This assignment asks you to design and implement a program that could be used for testing grade school students knowledge of multiplication tables.

The program will operate as follows:

1. The program will greet the student and ask for his/her first name. This name will be read into a string variable and would be used later as part of the report generated.

2. Then the program will present one multiplication table question at a time to the student, using a count controlled loop. The loop will run 10 times, but a named constant should be used to hold that value. The named constant should be used (rather that the literal constant 10) whenever that number is needed for loop control or calculations. The program will generate two random numbers (between 1 and 10) and pose the problem for those numbers like this:

What is 7 times 9 ?

The program then reads the answer typed by the student and compares it to the answer it calculates and provides one of two possible messages:

Your answer is correct!

or,

Your answer is wrong! The correct answer is 63.

3. Once the student has answered all the problems, the program will display a summary report for the student. The report will include:

  • Student's name
  • Number of problems attempted
  • Number of correct answers given
  • Number of incorrect answers given
  • A message saying one of the following:
    • Congratulations!, You got a perfect score. (if the student has answered all questions correctly)
    • You did all right. (If the student scored at least 80% but less than a perfect score).
    • You pass but should try to do better (if the student scored at least 70% but less than 80%)
    • You really need to study harder. (If the score is less than 70%)
  • It will display the customary sign-off message and exit.

Generating the problems

In a lab, we used the following statement to generate a value between 1 and 6:

face = 1 + rand.nextInt(NUM_FACES);

where rand is a random number generator. The rand.nextInt(NUM_FACES) method generates a random integer value between 0 and NUM_FACES 1 (with NUM_FACES = 6), so face will have a value between 1 and 6. So to generate a random integer (an integer value between 1 and 10) we can use the expression

1 + rand.nextInt(10)

with appropriate declarations.

Program Design

The program will use several functions (methods) to divide the problem into parts that can be solved separately. The following functions are required to be present:

  • static boolean oneProblem(int problemNumber) - This function will generate a problem, present it to the user, get user's response and provide the feedback (as in Item 2 above). It will return a Boolean value to indicate whether the student solved the problem correctly. This function will be called in a loop by the "main" function. The parameter is a problem sequence number sent by the main function (it can be the loop control variable).
  • static void report(String name, int numProbs, int numCorrect) - The parameters are: the name of the student, number of problems attempted, number of correct answers. From this information the function will generate the report required (see Item 3 above).

You may design and use more functions as you see fit.

Structure Diagram

The diagram here shows which function(s) call which other function(s). see image.

Academic Honesty!
It is not our intention to break the school's academic policy. Posted solutions are meant to be used as a reference and should not be submitted as is. We are not held liable for any misuse of the solutions. Please see the frequently asked questions page for further questions and inquiries.
Kindly complete the form. Please provide a valid email address and we will get back to you within 24 hours. Payment is through PayPal, Buy me a Coffee or Cryptocurrency. We are a nonprofit organization however we need funds to keep this organization operating and to be able to complete our research and development projects.