Problem Description Create the flowchart and program for an arithmetic quiz. The
ID: 3887353 • Letter: P
Question
Problem Description
Create the flowchart and program for an arithmetic quiz. The program will first ask the user which of four operations they want to test (addition, subtraction, multiplication, or division). The program will then create a ‘quiz’ with the indicated operation and two randomized, single digit, non-negative integers (for instance, if the user indicates multiplication, the quiz will be “What is x1*x2?” Where x1 and x2 are two randomized numbers). If the user enters a correct response to the question, the program congratulates the user. Otherwise, the program will say the answer is wrong and display the correct answer.
Assignment Requirements
Follow the following problem solving steps to aid in completing the assignment:
Draw a simple flowchart diagram showing the process flow of the program. You may use any software that is capable of drawing flowchart diagrams like draw.io or MS PowerPoint.
I strongly recommend creating the pseudo-code for this assignment before beginning coding.
You may use either Scanner or JOptionPane to accept user input and display output.
You will need to provide screenshots of 5 test runs (+, -, *, /, and incorrect answer)
Do not forget your program header
Run and create screenshots of the following test cases
Operation
User Response
Test case 1
+
Correct
Test case 2
-
Correct
Test case 3
*
Correct
Test case 4
/
Correct
Test case 5
Any
Wrong
Example Runs of the Program
Output: What operation? (1 for addition, 2 for subtraction, 3 for multiplication, 4 for division)
Input: 2
Output: What is 8-4?
Input: 4
Output: Correct! Good job! Yay! You did it!
Output: What operation? (1 for addition, 2 for subtraction, 3 for multiplication, 4 for division)
Input: 3
Output: What is 3*9?
Input: 15
Output: Incorrect, the answer is 27.
Operation
User Response
Test case 1
+
Correct
Test case 2
-
Correct
Test case 3
*
Correct
Test case 4
/
Correct
Test case 5
Any
Wrong
Explanation / Answer
import java.util.Random;
import java.util.Scanner;
public class ArithmeticQuiz {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner scanner = null;
try {
scanner = new Scanner(System.in);
System.out
.print("What operation? (1 for addition, 2 for subtraction, 3 for multiplication, 4 for division):");
int choice = scanner.nextInt();
Random rand = new Random();
int x = rand.nextInt(10);
int y = rand.nextInt(10);
double result;
switch (choice) {
case 1:
System.out.print("What is " + x + "+" + y + "? ");
result = scanner.nextInt();
if ((x + y) == result) {
System.out.println("Correct! Good job! Yay! You did it!");
} else {
System.out.println("Incorrect, the answer is " + (x + y)
+ ".");
}
break;
case 2:
System.out.print("What is " + x + "-" + y + "? ");
result = scanner.nextInt();
if ((x - y) == result) {
System.out.println("Correct! Good job! Yay! You did it!");
} else {
System.out.println("Incorrect, the answer is " + (x - y)
+ ".");
}
break;
case 3:
System.out.print("What is " + x + "*" + y + "? ");
result = scanner.nextInt();
if ((x * y) == result) {
System.out.println("Correct! Good job! Yay! You did it!");
} else {
System.out.println("Incorrect, the answer is " + (x * y)
+ ".");
}
break;
case 4:
System.out.print("What is " + x + "/" + y + "? ");
result = scanner.nextDouble();
if (((double) x / y) == result) {
System.out.println("Correct! Good job! Yay! You did it!");
} else {
System.out.println("Incorrect, the answer is "
+ ((double) x / y) + ".");
}
break;
default:
System.out.println("Invalid Choice");
break;
}
} catch (Exception e) {
// TODO: handle exception
}
}
}
OUTPUT:
Test 1:
What operation? (1 for addition, 2 for subtraction, 3 for multiplication, 4 for division):1
What is 3+8? 11
Correct! Good job! Yay! You did it!
Test 2:
What operation? (1 for addition, 2 for subtraction, 3 for multiplication, 4 for division):2
What is 5-8? 3
Incorrect, the answer is -3.
Test 3:
What operation? (1 for addition, 2 for subtraction, 3 for multiplication, 4 for division):3
What is 4*9? 36
Correct! Good job! Yay! You did it!
Test 4:
What operation? (1 for addition, 2 for subtraction, 3 for multiplication, 4 for division):4
What is 3/3? 1
Correct! Good job! Yay! You did it!
Test 5:
What operation? (1 for addition, 2 for subtraction, 3 for multiplication, 4 for division):6
Invalid Choice
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.