In: Computer Science
Exercise Overview
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
Technical Requirements
The system should include the following Java components:
Example output (from the Eclipse console)
Enter your name: Kevin
Enter "A" for Addition, "S" for Subtraction, "M" for Multiplication, "D" for Division: M
Enter the number of problems you wish to work: 3
What are the low and high numbers you want in your problems?
Enter the low value for your problems: 0
Enter the high value for your problems: 10
10 * 0 = 0
Correct
2 * 3 = 5
Incorrect
8 * 9 = 72
Correct
Session Summary
3 problems, 2 correct
Score is 67, Time is 11 seconds
Session for Kevin was Multiplication on 2020-08-24 at 00:09:40.401
------ Please help me answer the questions below as well. ------
Testing. Describe how you tested this program.
Analysis. Describe the problem including input, processing, primary calculations, and output in your own words.
Design. Describe the major steps for solving the problem.
JAVA PROGRAM ===>
import java.util.Scanner;
import java.util.concurrent.TimeUnit;
import java.time.format.DateTimeFormatter;
import java.time.LocalDateTime;
public class Question {
public static void main(String arg[]) {
String name;
Scanner sc = new
Scanner(System.in);
int num,max,min,count=0;
double num1,num2;
double ans,result;
String str ="";
System.out.print("Enter your name :
");
name = sc.nextLine();
System.out.println("Enter \"A\" for
Addition, \"S\" for Subtraction, \"M\" for Multiplication, \"D\"
for Division: M");
System.out.print("Enter : ");
char ch = sc.next().charAt(0); //
input choice for operation
System.out.print("Enter the number
of problems you wish to work : ");
num = sc.nextInt();
System.out.println("What are the
low and high numbers you want in your problems?");
System.out.print("Enter the low
value for your problems : ");
min = sc.nextInt();
System.out.print("Enter the high
value for your problems : ");
max = sc.nextInt();
long startTime = System.nanoTime();
// start session for questions
if(ch == 'A')
{
str =
"Addition";
for(int
i=0;i<num;i++)
{
num1 = (int)(Math.random() * (max - min + 1) +
min);
num2 = (int)(Math.random() * (max - min + 1) +
min);
System.out.print((int)num1 +" + "+ (int)num2 +"
= ");
ans = sc.nextDouble();
if(ans == (num1+num2))
{
count++;
System.out.println("Correct");
}
else
{
System.out.println("Incorrect");
}
}
}
else if(ch == 'S')
{
str =
"Subtraction";
for(int
i=0;i<num;i++)
{
num1 = (int)(Math.random() * (max - min + 1) +
min);
num2 = (int)(Math.random() * (max - min + 1) +
min);
System.out.print((int)num1 +" - "+ (int)num2 +"
= ");
ans = sc.nextDouble();
if(ans == (num1-num2))
{
count++;
System.out.println("Correct");
}
else
{
System.out.println("Incorrect");
}
}
}
else if(ch == 'M')
{
str =
"Multipication";
for(int
i=0;i<num;i++)
{
num1 = (int)(Math.random() * (max - min + 1) +
min);
num2 = (int)(Math.random() * (max - min + 1) +
min);
System.out.print((int)num1 +" * "+ (int)num2 +"
= ");
ans = sc.nextDouble();
if(ans == (num1*num2))
{
count++;
System.out.println("Correct");
}
else
{
System.out.println("Incorrect");
}
}
}
else if(ch == 'D')
{
str =
"Division";
for(int
i=0;i<num;i++)
{
num1 = (int)(Math.random() * (max - min + 1) +
min);
num2 = (int)(Math.random() * (max - min + 1) +
min);
System.out.print((int)num1 +" / "+ (int)num2 +"
= ");
ans = sc.nextDouble();
result = (num1/num2);
double result1 =
Math.round(result*1000.0)/1000.0;
if(ans == result1 )
{
count++;
System.out.println("Correct
"+result1);
}
else
{
System.out.println("Incorrect
"+result1);
}
}
}
else
{
System.out.println("Wrong Input !");
}
long endTime = System.nanoTime();
// sessio end for question
System.out.println("");
System.out.println("Session Summary
: ");
System.out.println(num+"
problems,"+count+" correct");
double avg =
(count*1.0/num*1.0)*100;
long totalTime = endTime -
startTime; // calculate time in nanoseconds
long seconds =
TimeUnit.NANOSECONDS.toSeconds(totalTime); // convert time
nanoseconds to seconds
System.out.println("Score is
"+(Math.round(avg)) +", Time is : "+seconds+" seconds");
DateTimeFormatter dtf =
DateTimeFormatter.ofPattern("yyyy/MM/dd HH:mm:ss"); // date
LocalDateTime now =
LocalDateTime.now(); // local time
System.out.println("Session for
"+name+" was "+str+" on "+dtf.format(now));
}
}
OUTPUT SCREENSHOT ===>