70.3k views
5 votes
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 im

User Mvo
by
4.9k points

1 Answer

0 votes

import java.util.Scanner;

public class JavaApplication44 {

public static void main(String[] args) {

Scanner scan = new Scanner(System.in);

System.out.print("Enter you name: ");

String name = scan.nextLine();

System.out.print("Enter your operation (+,-,*,/): ");

String operator = scan.nextLine();

System.out.print("Enter the range of the problems: ");

int ran = scan.nextInt();

System.out.print("Enter number of problems: ");

int problems = scan.nextInt();

int score = 0;

for (int i = 1; i <= ran; i++){

int first = (int)(Math.random()*ran);

int sec = (int)(Math.random()*ran);

System.out.print("Problem #"+i+": "+first + " "+operator+" "+sec+" = ");

int ans = scan.nextInt();

if (operator.equals("+")){

if (ans == first + sec){

System.out.println("Correct!");

score++;

}

else{

System.out.println("Wrong. The correct answer is "+(first+sec));

}

}

else if(operator.equals("-")){

if (ans == first - sec){

System.out.println("Correct");

score++;

}

else{

System.out.println("Wrong. The correct answer is "+(first - sec));

}

}

else if (operator.equals("*")){

if (ans == first * sec){

System.out.println("Correct");

score++;

}

else{

System.out.println("Wrong. The correct answer is "+(first * sec));

}

}

else if (operator.equals("/")){

if (ans == first / sec){

System.out.println("Correct");

score++;

}

else{

System.out.println("Wrong. The correct answer is "+(first / sec));

}

}

}

System.out.println(name+", you answered "+score+" questions correctly.");

}

}

I hope this helps!

User Nsconnector
by
5.0k points