Question
Write a calculator program in Java that will evaluate simple expressions with 2 operands and 1 operator such as 17 + 3 and 4 *
Write a calculator program in Java that will evaluate simple expressions with 2 operands and 1 operator such as 17 + 3 and 4 * 9. You must display a menu with the choices as shown in the sample run. You must use integers to store the 2 operands and a double to store the result. You must use an explicit type cast for the floating-point division in option 4. You must use a switch statement to process the menu choices. After each computation, the menu will be displayed and another calculation will be performed until the user selects option 5 to exit the system.
Your sample runs must follow the exact format.
Sample Run:
Choose from the following:
1. Add 2 integers
2. Subtract 2 integers
3. Multiply 2 integers
4. Divide 2 integers
5. Exit
Enter choice: 1
Enter first integer: 20
Enter second integer: 22
20 + 22 = 42.0
Choose from the following:
1. Add 2 integers
2. Subtract 2 integers
3. Multiply 2 integers
4. Divide 2 integers
5. Exit
Enter choice: 4
Enter first integer: 2
Enter second integer: 3
2 / 3 = 0.6666666666666666
Choose from the
following:
1. Add 2 integers
2. Subtract 2 integers
3. Multiply 2 integers
4. Divide 2 integers
5. Exit
Enter choice: 2
Enter first integer: 12
Enter second integer: 20
12 20 = -8.0
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started