In: Computer Science
FlashCards with Classes and Exception Handling – Project
Project Overview
Create at least 2 object classes (Session and Problems) and one driver class and ensure the user inputs cannot cause the system to fail by using exception handling.
Overview from Project . Implement a Java program that creates math flashcards for elementary grade students. User will enter his/her name, the type (+,-, *, /), the range of the factors to be used in the problems, and the number of problems to work. The system will provide problems, evaluate user responses to the problems, score the problems, and provide statistics about the session at the end.
Functional Requirements
Optional Functional Enhancement
You will notice in the Example Output below that an exit loop has been added, giving the user the option to continue with another session without having to restart the system. You may add this function to your system .
Technical Requirements
The system should include the following Java components:
The system should include the following Java components (most of these are new so ‘new’ is not specified for each):
Use the LocalDateTime class and the DateTimeFormatter class to display date and time of session
Optional Functional Enhancement
You will notice in the Example Output below that an exit loop has been added, giving the user the option to continue with another session without having to restart the system. You may add this function to your system .
Example output (from the Eclipse console)
Please enter your name: Kobe bryan
What operation would you like to work - A, S, M, or D? z
Must be A, S, M, or D. Try again.
What operation would you like to work - A, S, M, or D? &
Must be A, S, M, or D. Try again.
What operation would you like to work - A, S, M, or D? 1
Must be A, S, M, or D. Try again.
What operation would you like to work - A, S, M, or D? m
Enter number of problems: 0
Invalid entry. Try again
Enter number of problems: -3
Invalid entry. Try again
Enter number of problems: z
Invalid entry. Try again
Enter number of problems: 3
Enter low value for range of factors: -2
Invalid entry. Try again
Enter low value for range of factors: z
Invalid entry. Try again
Enter low value for range of factors: 0
Enter high value for range of factors: 9
7 * 5 = a
Invalid entry. Try again
7 * 5 = 12
incorrect
9 * 3 = 27
correct
1 * 1 = -1
Invalid entry. Try again
1 * 1 = &
Invalid entry. Try again
1 * 1 = 1
correct
Summary
Kevin Short 2020-10-16-21-41-07-669 Multiplication Range: 0 - 9 #Prob: 3 Correct: 2 Score: 66 Time: 27
7 * 5 = 12 A: 35 incorrect
9 * 3 = 27 A: 27 correct
1 * 1 = 1 A: 1 correct
Would you like to try another set of problems? Y/N? n
Thank you for playing! Play again soon.
Analysis. Describe any analysis that is required for solving the problem, including a discussion of key elements and complex statements or logic of the system.
Design. Describe the major steps for solving the problem (developing the code). A high-level outline of the classes and the variables and methods in the classes is recommended.
Testing. Describe how you tested the system.
I really appreciate you if you answer with the analysis, design and testing part .Thank you
PLEASE GIVE IT A THUMBS UP, I SERIOUSLY NEED ONE, IF YOU NEED ANY MODIFICATION THEN LET ME KNOW, I WILL DO IT FOR YOU

import java.util.*;
// Defines class FlashCards
class FlashCards {
  // Scanner class object created
  Scanner sc = new Scanner(System.in);
  // Function to displays menu, accepts user choice, validates it
  // and returns the user choice
  char menu() {
    char choice;
    // Loops valid choice entered by the user
    do {
      // Displays the menu
      System.out.print(
        "\n What operation would you like to work - " + "A, S, M, or D? "
      );
      // Converts to upper case
      choice = Character.toUpperCase(sc.next().charAt(0));
      // Checks if user choice is either 'A' or 'S' or 'M' or 'D' then valid
      if (
        choice == 'A' || choice == 'S' || choice == 'M' || choice == 'D'
      ) return choice; // Returns the choice
      // Otherwise displays error message
      else System.out.print("\n Must be A, S, M, or D. Try again.");
    } while (true); // End of do - while loop
  } // End of function
  // Function receives a message
  // Accepts a number validates it and returns it
  int validNumber(String message) {
    int num;
    // Loops till valid number entered by the user
    do {
      // try block begins
      try {
        // Displays the message
        System.out.print(message);
        // Accepts a number
        String data = sc.next();
        // Converts it to integer
        num = Integer.parseInt(data);
        // Checks if number is less than or equals to 0 then
        // throws NumberFormatException
        if (num <= 0) throw new NumberFormatException();
        // Otherwise valid number
        else return num; // returns the number
      } catch (NumberFormatException ex) { // Catch block to handle NumberFormatException // End of try block
        System.out.print("\n Invalid entry. Try again");
      } // End of catch block
    } while (true); // End of do - while loop
  } // End of function
  // main method definition
  public static void main(String[] s) {
    // Local variables to store data
    String name;
    int numberOfProblems;
    int lowValue, highValue;
    int correct;
    int score;
    int computedAnswer, userAnswer;
    double computedAnswerD, userAnswerD;
    long startTime, endTime, duration;
    String summary;
    String operation;
    // Creates an object of Random class
    Random rand = new Random();
    // Creates an object of class FlashCards
    FlashCards fc = new FlashCards();
    // Loops till user choice is not 'N' or 'n'
    do {
      // Resets summary and operation type to null for each game
      summary = operation = "";
      // Resets correct answer and score to 0 for each game
      correct = score = 0;
      // Accepts name of the player
      System.out.print("\n Please enter your name: ");
      name = fc.sc.next();
      // Calls the function to accept user choice for operation
      char choice = fc.menu();
      // Calls the function to accept number of problems
      numberOfProblems = fc.validNumber("\n Enter number of problems: ");
      // Calls the function to accept lower limit
      lowValue = fc.validNumber("\n Enter low value for range of factors: ");
      // Calls the function to accept higher limit
      highValue = fc.validNumber("\n Enter high value for range of factors: ");
      // Stores the start time
      startTime = System.currentTimeMillis();
      // Loops till number of questions
      for (int c = 0; c < numberOfProblems; c++) {
        // Generates a random number for first operand between low and high value
        int operandOne =
          rand.nextInt(highValue - lowValue + lowValue) + lowValue;
        // Generates a random number for second operand between low and high value
        int operandTwo =
          rand.nextInt(highValue - lowValue + lowValue) + lowValue;
        // Checks user selected operation
        switch (choice) {
          case 'A':
            // Stores the operation type
            operation = "Addition";
            // Calculates the sum
            computedAnswer = operandOne + operandTwo;
            // Calls the function to accept user answer passes question
            // as parameter
            userAnswer =
              fc.validNumber("\n " + operandOne + " + " + operandTwo + " = ");
            // Concatenates question, user answer, computed answer
            summary +=
              operandOne +
              " + " +
              operandTwo +
              " = " +
              userAnswer +
              " A: " +
              computedAnswer;
            // Checks if computed answer and user answer is same
            if (computedAnswer == userAnswer) {
              // Increase the correct answer counter by one
              correct++;
              // Adds score
              score += 33;
              // Concatenates status of answer as correct
              summary += " correct \n ";
              System.out.print("\n Correct");
            } // End of if condition
            // Otherwise wrong answer
            else {
              // Concatenates status of answer as incorrect
              summary += " incorrect \n ";
              System.out.print("\n Inorrect");
            } // End of else
            break;
          case 'S':
            // Stores the operation type
            operation = "Subtraction";
            // Calculates the subtraction
            computedAnswer = operandOne - operandTwo;
            // Calls the function to accept user answer passes question
            // as parameter
            userAnswer =
              fc.validNumber("\n " + operandOne + " - " + operandTwo + " = ");
            // Concatenates question, user answer, computed answer
            summary +=
              operandOne +
              " - " +
              operandTwo +
              " = " +
              userAnswer +
              " A: " +
              computedAnswer;
            // Checks if computed answer and user answer is same
            if (computedAnswer == userAnswer) {
              // Increase the correct answer counter by one
              correct++;
              // Adds score
              score += 33;
              // Concatenates status of answer as correct
              summary += " correct \n ";
              System.out.print("\n Correct");
            } // End of if condition
            // Otherwise wrong answer
            else {
              // Concatenates status of answer as incorrect
              summary += " incorrect \n";
              System.out.print("\n Inorrect");
            } // End of else
            break;
          case 'M':
            // Stores the operation type
            operation = "Multiplication";
            // Calculates the product
            computedAnswer = operandOne * operandTwo;
            // Calls the function to accept user answer passes question
            // as parameter
            userAnswer =
              fc.validNumber("\n " + operandOne + " * " + operandTwo + " = ");
            // Concatenates question, user answer, computed answer
            summary +=
              operandOne +
              " * " +
              operandTwo +
              " = " +
              userAnswer +
              " A: " +
              computedAnswer;
            // Checks if computed answer and user answer is same
            if (computedAnswer == userAnswer) {
              // Increase the correct answer counter by one
              correct++;
              // Adds score
              score += 33;
              // Concatenates status of answer as correct
              summary += " correct \n ";
              System.out.print("\n Correct");
            } // End of if condition
            // Otherwise wrong answer
            else {
              // Concatenates status of answer as incorrect
              summary += " incorrect \n";
              System.out.print("\n Inorrect");
            } // End of else
            break;
          case 'D':
            // Stores the operation type
            operation = "Division";
            // Calculates the division
            computedAnswerD = operandOne / operandTwo;
            // Calls the function to accept user answer passes question
            // as parameter
            userAnswerD =
              fc.validNumber("\n " + operandOne + " / " + operandTwo + " = ");
            // Concatenates question, user answer, computed answer
            summary +=
              operandOne +
              " / " +
              operandTwo +
              " = " +
              userAnswerD +
              " A: " +
              computedAnswerD;
            // Checks if computed answer and user answer is same
            if (computedAnswerD == userAnswerD) {
              // Increase the correct answer counter by one
              correct++;
              // Adds score
              score += 33;
              // Concatenates status of answer as correct
              summary += " correct \n ";
              System.out.print("\n Correct");
            } // End of if condition
            // Otherwise wrong answer
            else {
              // Concatenates status of answer as incorrect
              summary += " incorrect \n ";
              System.out.print("\n Inorrect");
            } // End of else
            break;
        } // End of switch - case
      } // End of for loop
      // Stores the stop time
      endTime = System.currentTimeMillis();
      // Calculates time taken
      duration = (endTime - startTime) / 1000;
      // Displays summary
      System.out.print("\n Summary\n");
      System.out.print(
        " " +
        name +
        new Date() +
        " " +
        operation +
        " Range: " +
        lowValue +
        " - " +
        highValue +
        " #Prob: " +
        numberOfProblems +
        " Correct: " +
        correct +
        " Score: " +
        score +
        " Time: " +
        duration
      );
      System.out.print("\n " + summary);
      // Accepts user choice to continue or not
      System.out.print(
        "\n Would you like to try another set of problems? Y/N? "
      );
      char ch = fc.sc.next().charAt(0);
      // Converts to upper case
      ch = Character.toUpperCase(ch);
      // Checks if user choice is 'N' then come out of the loop
      if (ch == 'N') break;
    } while (true); // End of do - while loop
    System.out.print("\n Thank you for playing! Play again soon.");
  } // End of main method
} // End of class