Write a simple calculator which supports add subtract multiply and divide. Prompt the user for two numbers and an operation. Use number 1-4 for menu options. If divide is selected and the second number is zero, output an error message. If an invalid menu option is selected, output an error message. If all is well, perform the operation and output the result to one decimal. Please write in Java that results like test case examples. Thanks

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question
Write a simple calculator which supports add subtract multiply and divide. Prompt the user for two numbers and an operation. Use number 1-4 for menu options. If divide is selected and the second number is zero, output an error message. If an invalid menu option is selected, output an error message. If all is well, perform the operation and output the result to one decimal. Please write in Java that results like test case examples. Thanks
Test Case 4
Enter first number \n
Enter your se
9 ENTER
Enter second number \n
3 ENTER
Enter a menu option\n
[1] Add \n
[2] Subtract \n
[3] Multiply \n
[4] Divide \n
4 ENTER
9.0 / 3.0 = 3.0 \n
Test Case 5
Enter first number \n
10 ENTER
Enter second number \n
ENTER
Enter a menu option \n
[1] Add \n
[2] Subtract \n
[3] Multiply \n
[4] Divide \n
4 ENTER
If division is selected the second number cannot be zero \n
Transcribed Image Text:Test Case 4 Enter first number \n Enter your se 9 ENTER Enter second number \n 3 ENTER Enter a menu option\n [1] Add \n [2] Subtract \n [3] Multiply \n [4] Divide \n 4 ENTER 9.0 / 3.0 = 3.0 \n Test Case 5 Enter first number \n 10 ENTER Enter second number \n ENTER Enter a menu option \n [1] Add \n [2] Subtract \n [3] Multiply \n [4] Divide \n 4 ENTER If division is selected the second number cannot be zero \n
Test Case 7
Enter first number \n
10.5 ENTER
Enter second number \n
3.1 ENTER
Enter a menu option \n
[1] Add \n
[2] Subtract \n
[3] Multiply \n
[4] Divide \n|
4 ENTER
10.5/ 3.1 = 3.4 \n
Test Case 8
Enter first number \n
0 ENTER
Enter second number\n
25 ENTER
Enter a menu option \n
[1] Add \n
[2] Subtract \n
[3] Multiply \n
[4] Divide \n
5 ENTER
Invalid menu option
Transcribed Image Text:Test Case 7 Enter first number \n 10.5 ENTER Enter second number \n 3.1 ENTER Enter a menu option \n [1] Add \n [2] Subtract \n [3] Multiply \n [4] Divide \n| 4 ENTER 10.5/ 3.1 = 3.4 \n Test Case 8 Enter first number \n 0 ENTER Enter second number\n 25 ENTER Enter a menu option \n [1] Add \n [2] Subtract \n [3] Multiply \n [4] Divide \n 5 ENTER Invalid menu option
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps with 3 images

Blurred answer
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education