Exercise Overview

Implement a Java program that creates math flashcards for elementary grade students. User will enter his/her name, the type of problems to be worked (A, S, M, or D), the range of the factors to be used in the problems, and the number of problems to work. The system will present problems, evaluate user responses to the problems, score the problems, and provide statistics about the session at the end.

Important note: You may assume the user enters logical responses to every prompt, meaning no exception checks or handling are required.

Functional Requirements // These are what the user sees.

  • User is prompted for and enters name at the beginning of a session.
  • User enters their choice of the four math operations - addition, subtraction, multiplication, and division. Only one type of problem can be done in each session.
  • User will enter additional session parameters from prompts - number of problems to work and the range of values desired in the problems, e.g., addition with factors ranging from 0 to 12.
  • System presents problems to the user consistent with the entered parameters.
  • User will respond to problems with an answer and the system will provide immediate feedback for each problem, correct or incorrect.
  • System will provide summary statistics for the session once all problems are completed, including number of problems, number of correct problems, percentage score, and a list of the problems in the user session.

Technical Requirements // These requirements happen in the background.

The system should include the following Java components:

Name your source code main class (the .java file) as follows: YourName_Project1.java.

Comments outline the sections of the system.

  • Include comments at the beginning of the program to provide a 1- or 2-sentence description of the system and identify the developer of the system (you).

Design - major system sections

  • Instantiate objects (e.g., Scanner and Random)
  • Declare variables
  • Prompt for and read-in user-entered parameters
  • Print the parameters and introduction
  • Start the loop for the number of problems
    • Generate problems
    • Read-in user responses
    • Evaluate and update running score
  • After end of loop, print summary statistics, problem history, and outro message.

Code-specific technical requirements

  • Suggested variables
    • String name
    • String probType (values A, S, M, or D)
    • String longProbType (values addition, subtraction, multiplication, or division), based on probType using switch
    • int numProb - the number of problems to be worked
    • int loFactor - lowest possible value for a factor
    • int hiFactor - highest possible value for a factor
    • int factor1 - a random value within the loFactor and hiFactor range
    • int factor2 - a random value within the loFactor and hiFactor range
    • int answer - the correct answer to the generated problem
    • int response - the user-entered response to the problem
    • int score - the running total of correct answers
    • double scorePct - the percentage of responses that are correct
    • String[] history = new String[numProb] - used to store the problems as they are worked and then printed after the summary statistics; this array must be declared after the user assigns numProb variable a value
  • Suggested algorithms or code sections
    • factor1 or factor2 = random.nextInt(hiFactor - loFactor + 1) + loFactor;
    • probType = probType.toUpperCase(); so you need only switch on the uppercase value
    • Use switch(probType) to set the longProbType
    • Use a second switch(probType) to create the problems for the different problem types

Example output (from the Eclipse console)

Enter your name: Kevin
What is the type of problem you wish to work? Enter A, S, M, or D: d
Enter the lowest factor value for your flashcard problems: 0
Enter the highest factor value for your flashcard problems: 9
Enter the number of problems you wish to work: 3

Hi Kevin, and welcome to the 3312 FlashCard System!
You have chosen the operation Division.
The range of factors you have chosen is from 0 to 9, inclusive.
You have chosen to work 3 problems.
Press any character key and then Enter to begin.
a

24 / 8 = 3
Correct!

9 / 3 = 3
Correct!

30 / 6 = 4
Incorrect! Correct answer is 5

Session Summary
3 problems, 2 correct
Score is 66.7

Problems
24 / 8 = 3, Correct, correct answer is 3
9 / 3 = 3, Correct, correct answer is 3
30 / 6 = 4, Incorrect, correct answer is 5

Thank you for using the 3312 FlashCard System, Kevin.
Come back and play again real soon!

Hints.

  • To create your problems, code the addition case first for just one problem (no loop yet). Then replicate and edit for the problem types using switch(probType) for the selection process. Then add the loop for the number of problems.
  • For the subtraction case, generate the factors, add them together so the sum becomes the minuend (the bigger number), one of the factors is the subtrahend (number subtracted from the bigger number), and the other factor is the difference (the answer).
  • For the division case, use the product of the factors for the dividend (the bigger number), one factors becomes the divisor (the smaller number), and the other factor is the quotient (the answer).
  • Add logic to prevent division-by-zero. Approach options:
    • Use if statement to check for zero, then add a 1 to the factor
    • Use a while loop with the test (factor == 0) and with the body of the if statement generate a new factor until it is non-zero (this is the best approach)
  • To maximize reusable code, try to minimize the amount of code within the switch cases.

Research and Analysis.

Describe your analysis of specific issues within the overall coding problem including input, processing, primary calculations, and output in your own words. List any websites or other resources you consulted in doing your analysis.

Suggested areas for analysis:

  • Generating a random int within a range
  • Creating a String value for each problem that can be an element in the history array
  • Calculating the scorePct using type casting
  • Using the System.out.printf() method for printing the scorePct value

Type your analysis topics and descriptions here. Remember to list resources consulted.

Design.

Describe the major steps for solving the problem.

  • Describe the major sections of the code, and include important subsections within the major sections

Testing.

Describe how you tested this program. Suggested areas for explicit testing:

  • Generating the random integers to be sure they are within the user-entered range
  • Ensuring that division-by-zero prevention logic is working correctly
  • Did you use the debugger for any sections?
  • Did you do interim testing by printing extra variables to the console and then comment them out before submitting your final version of code?
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.