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

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!