Question

In: Computer Science

Exercise Overview Implement a Java program that creates math flashcards for elementary grade students. User will...

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

  • User enters name at the beginning of a session.
  • System covers four math operations – addition, subtraction, multiplication, and division – with the user choosing which of the four operations to do in the session. Only 1 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 will present problems to the user.
  • 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 user name, date and time, operation chosen for the problems, range selected for the problems, number of problems, number of problems correct, percentage score, duration of the session.

Technical Requirements

The system should include the following Java components:

  • Name of your source code main class as follows: YourName_Project1.java
  • Methods to prompt the user and to get values for input variables, e.g., user name, number of problems, range of values, etc.
  • Switch statement for selecting the math operation to perform (cases).
  • Loop to create the selected number of problems for the session,
  • Method to get the factors for the problems.
  • Math.random() used in the creation of the problems.
  • System.currentTimeMillis() used to record the start time, end time, and calculate the duration of the session in seconds.
  • java.time.LocalTime.now() method to display date and time of session.

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.

Solutions

Expert Solution

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 ===>


Related Solutions

Design and implement a Java program that creates a GUI that will allow a customer to...
Design and implement a Java program that creates a GUI that will allow a customer to order pizza and other items from a Pizza Paarlor. The customer should be able to order a variety of items which are listed below. The GUI should allow the customer (viaJavaFX UI Controls - text areas, buttons, checkbox, radio button, etc.) to input the following information: Name of the customer First Name Last Name Phone number of the customer Type of food being order...
Need a program in java that creates a random addition math quiz The program should ask...
Need a program in java that creates a random addition math quiz The program should ask the user to enter the following The smallest and largest positive numbers to be used when generating the questions - The total number of questions to be generated per quiz - The total number of the quiz's to create from then the program should generate a random math (Just addition) quiz from what the user entered
write a java program to evaluate the highest number input by user, cannot use math class,...
write a java program to evaluate the highest number input by user, cannot use math class, must use overloading . Must compute four computeHighNum methods. Here is what I have. import java.util.Scanner; public class Overload { public static void main(String[] args){ Scanner input = new Scanner(System.in); int number1 = input.nextInt(); int number2 = input.nextInt(); int number3 = input.nextInt();    //int maximum = maximum(number1, number2 ); System.out.printf("Highest integer is ");       // int number1 = input.nextInt(); // int number2 =...
Java Program. Sentinel While Loop Lab Do the following: Prompts the user to enter a grade...
Java Program. Sentinel While Loop Lab Do the following: Prompts the user to enter a grade or a -1 to quit. IF the user entered a -1 THEN Display a message that the User is done entering grades ELSE Count each grade as it is entered. Compute a running total of the grades entered. END IF After the user enters the sentinel of -1, calculate the average of the grades entered. When computing the average, make sure that there is...
Java - Design and implement an application that creates a histogram that allows you to visually...
Java - Design and implement an application that creates a histogram that allows you to visually inspect the frequency distribution of a set of values. The program should read in an arbitrary number of integers that are in the range 1 to 100 inclusive; then produce a chart similar to the one below that indicates how many input values fell in the range 1 to 10, 11 to 20, and so on. Print one asterisk for each value entered. Sample...
Create an application that asks a user to answer 5 math questions. JAVA
Create an application that asks a user to answer 5 math questions. JAVA
An elementary principal is interested in determining if pulling 5th and 6th grade students out of...
An elementary principal is interested in determining if pulling 5th and 6th grade students out of class to participate in music classes (e.g., orchestra, band, choir) has a significant impact on their course grades. Twenty students from the two grades miss math class once per week due to music. The average grade for math class among all students is 80%. Do these music students have significantly different grades than the rest of the students (m=80, s=8). Test at the .01...
Write a Java Program to place a pizza ordering program. It creates a pizza ordered to...
Write a Java Program to place a pizza ordering program. It creates a pizza ordered to the specifications that the user desires. It walks the user through ordering, giving the user choices, which the program then uses to decide how to make the pizza and how much the cost of the pizza will be. Note: Use dialog boxes for communicating with the user. Remember to use the JOptionPane class which is the graphical user interface (GUI) and Comments that are...
Write a Java Program to place a pizza ordering program. It creates a pizza ordered to...
Write a Java Program to place a pizza ordering program. It creates a pizza ordered to the specifications that the user desires. It walks the user through ordering, giving the user choices, which the program then uses to decide how to make the pizza and how much the cost of the pizza will be. Note: Use dialog boxes for communicating with the user. Remember to use the JOptionPane class which is the graphical user interface (GUI) and Comments that are...
Give an example of a program in java that creates a GUI with at least one...
Give an example of a program in java that creates a GUI with at least one button and several textfields. Some of the textfields should be for input and others for output. Make the output textfields uneditable. When the button is clicked, the input fields should be read, some calculation performed and the result displayed in the output textfield(s).
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT