+1 (315) 557-6473 

Program To Maths Flash Cards, Using Java Programming Language Assignment Solutions.


Instructions

Objective
Write a program to create maths flash cards, in Java programming language.

Requirements and Specifications

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.
Source Code
package p1;
import java.util.Random;
import java.util.Scanner;
public class YourName_Project2 {
    // Author: Kevin Short
    // Description: This program generates flashcards for the user, evaluates the user's responses to the
    // flashcards, keeps a running score, and prints the final statistics for the user's session.
    public static void main(String[] args) {
        Cards cards = new Cards();
        Session session = new Session();
        session.setInputs(cards);
        session.prtIntro(cards);
        session.prtSummary();
        session.prtHistoryAndOutro();
    } // End of main method
} // End of class
class Session {
    private Scanner input = new Scanner(System.in);
    private String name;
    private String probType;
    private String longProbType;
    private String oper;
    private int loFactor;
    private int hiFactor;
    private int numProb;
    private int score;
    private double scorePct;
    private String[] history;
    public Session() {
    }
    public void setInputs(Cards c) {
        // Prompt for and read-in all inputs in one method
        // Prompt for and read-in user entered parameters
        // Prompt for and read-in the student's name
        System.out.print("Enter your name: ");
        name = input.next();
        // Prompt for and read-in the problem type (A, S, M, D)
        System.out.print("What is the type of problem you wish to work ? Enter A, S, M, or D: ");
        probType = input.next();
        probType = probType.toUpperCase(); // Convert the probType to uppercase
        // Use switch(probType) to update the longProbType var
        switch (probType) {
            case ("A"):
                longProbType = "Addition";
                oper = " + ";
                break;
            case ("S"):
                longProbType = "Subtraction";
                oper = " - ";
                break;
            case ("M"):
                longProbType = "Multiplication";
                oper = " * ";
                break;
            case ("D"):
                longProbType = "Division";
                oper = " / ";
                break;
        }
        // Prompt for and read-in the low and high factor range
        System.out.print("Enter the lowest factor value for your flashcard problems: ");
        loFactor = input.nextInt();
        c.setLoFactorRange(loFactor);
        System.out.print("Enter the highest factor value for your flashcard problems: ");
        hiFactor = input.nextInt();
        c.setHiFactorRange(hiFactor);
        // Prompt for and read-in the number of problems to be worked
        System.out.print("Enter the number of problems you wish to work: ");
        numProb = input.nextInt();
        history = new String[numProb]; // Need to set array size after read -in numProb
    }
    public String getName() {
        return name;
    }
    public String getProbType() {
        return probType;
    }
    public String getLongProbType() {
        return longProbType;
    }
    public String getOper() {
        return oper;
    }
    public int getNumProb() {
        return numProb;
    }
    public void prtIntro(Cards c) {
        System.out.println();
        System.out.println();
        // and then start the FlashCard system
        System.out.println(" Hi " + name + ", and welcome to the 3312 FlashCard System !");
        System.out.println(" You have chosen the operation" + longProbType + ".");
        System.out.println(" The range of factors you have chosen is from " + loFactor + " to " + hiFactor + ", inclusive.");
        System.out.println(" You have chosen to work " + numProb + " problems.");
        System.out.println(" Press any character key and then Enter to begin.");
        input.next();
        System.out.println();
        for (int i = 0; i < numProb; i++) {
            c.setProb(this);
            System.out.println();
            System.out.print(c.getA() + oper + c.getB() + " = ");
            c.setResponse(this);
            setHistory(c, i);
        }
        System.out.println();
        System.out.println();
        setScorePct();
    }
    public void incScore() {
        score++;
    }
    public void setHistory(Cards c, int i) {
        history[i] = c.getA() + oper + c.getB() + " = " + c.getResponse() + ", " + c.getCorInc() + ", correct answer is " + c.getC();
    }
    public void setScorePct() {
        scorePct = 100.0 * score / numProb;
    }
    public double getScorePct() {
        return scorePct;
    }
    public int getScore() {
        return score;
    }
    public void prtSummary() {
        System.out.println("Session Summary");
        System.out.println(numProb + " problems, " + score + "correct");
        System.out.printf("Score is %5.1f \n", scorePct);
        System.out.println();
    }
    public void prtHistoryAndOutro() { // Print history and outro message in one method
        // Print the history array
        System.out.println("Problems");
        for (int i = 0; i < numProb; i++) {
            System.out.println(history[i]);
        }
        System.out.println();
        System.out.println();
        System.out.println("Thank you for using the 3312 FlashCard System, " + name + ".");
        System.out.println("Come back and play again real soon!");
    }
}
class Cards {
    private Scanner input = new Scanner(System.in);
    private Random random = new Random();
    private int loFactor;
    private int hiFactor;
    private int factor1;
    private int factor2;
    private int answer;
    private int response;
    private int a = 0, b = 0, c = 0;
    private String corInc = "Incorrect";
    public Cards() {
    }
    public void setLoFactorRange(int lo) {
        this.loFactor = lo;
    }
    public void setHiFactorRange(int hi) {
        this.hiFactor = hi;
    }
    public void setFactors() {
        setFactor1();
        setFactor2();
    }
    public void setFactor1() { // For problems with division by zero to set only 1 factor
        factor1 = random.nextInt(hiFactor - loFactor + 1) + loFactor;
    }
    public void setFactor2() { // For problems with division by zero to set only 1 factor
        factor2 = random.nextInt(hiFactor - loFactor + 1) + loFactor;
    }
    public int getFactor1() {
        return factor1;
    }
    public int getFactor2() {
        return factor2;
    }
    public void setProb(Session s) { // Includes switch and the cases for the probTypes
        String probType = s.getProbType();
        switch (probType) {
            case "A":
                setFactors();
                a = factor1;
                b = factor2;
                c = factor1 + factor2;
                answer = c;
                break;
            case "S":
                setFactors();
                a = factor1 + factor2;
                b = factor1;
                c = factor2;
                answer = c;
                break;
            case "M":
                setFactors();
                a = factor1;
                b = factor2;
                c = factor1 * factor2;
                answer = c;
                break;
            case "D":
                while (factor1 == 0) {
                    setFactor1();
                }
                setFactor2();
                a = factor1 * factor2;
                b = factor1;
                c = factor2;
                answer = c;
                break;
        }
    }
    public void setResponse(Session s) {
        response = input.nextInt();
        if (response == answer) {
            s.incScore();
            corInc = "Correct";
        } else {
            corInc = "Incorrect";
        }
        System.out.println(corInc + "!");
    }
    public int getA() {
        return a;
    }
    public int getB() {
        return b;
    }
    public int getC() {
        return c;
    }
    public int getResponse() {
        return response;
    }
    public String getCorInc() {
        return corInc;
    }
}