Te a program This calculator is limited to the following functions: ➤ Addition Subtraction Multiplication Division Your program requires a total of 6 methods (INCLUDING THE MAIN These methods are listed and explained below: o The main method which will perform the following actions: ► Declare necessary variables (number1, number2, choice, answer) Welcome the user ► Prompt for the first number (double)

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
Instructions
Write a program that simulates a simple calculator.
This calculator is limited to the following functions:
Addition
Subtraction
Multiplication
Division
Your program requires a total of 6 methods (INCLUDING THE MAIN)
These methods are listed and explained below:
o The main method which will perform the following actions:
► Declare necessary variables (number1, number2, choice, answer)
Welcome the user
Prompt for the first number (double)
➤ Prompt for the second number (double)
Prompt for the arithmetic choice (int)
Validate the choice prompt using a do while loop (1-4 are VALID entries)
Create ONE control structure to determine which method to call based on users
input to choice variable
➤ Call display Results method passing the answer variable to display the answer.
o Four methods of type double which take as arguments the users two doubles
and returns the appropriate calculation. Hint these methods will all be very
similar, apart from the math.
public static double calcSum(double d1, double d2)
public static double calcSub(double d1, double d2)
public static double calcMul(double d1, double d2)
public static double calcDiv(double d1, double d2)
o One method of type void which will take as an argument the double variable
from the main methods which pertains to the users answer (a method call itself)
> public static void displayResults(double ans)
Transcribed Image Text:Instructions Write a program that simulates a simple calculator. This calculator is limited to the following functions: Addition Subtraction Multiplication Division Your program requires a total of 6 methods (INCLUDING THE MAIN) These methods are listed and explained below: o The main method which will perform the following actions: ► Declare necessary variables (number1, number2, choice, answer) Welcome the user Prompt for the first number (double) ➤ Prompt for the second number (double) Prompt for the arithmetic choice (int) Validate the choice prompt using a do while loop (1-4 are VALID entries) Create ONE control structure to determine which method to call based on users input to choice variable ➤ Call display Results method passing the answer variable to display the answer. o Four methods of type double which take as arguments the users two doubles and returns the appropriate calculation. Hint these methods will all be very similar, apart from the math. public static double calcSum(double d1, double d2) public static double calcSub(double d1, double d2) public static double calcMul(double d1, double d2) public static double calcDiv(double d1, double d2) o One method of type void which will take as an argument the double variable from the main methods which pertains to the users answer (a method call itself) > public static void displayResults(double ans)
✰✰
D
Your program should compile with no errors & make use of methods to earn full
points.
Hint: The 4 methods calcSum, calcSub, calcMul, calcDiv are essentially the same method with very
minor changes needed!
Z02NLabAssignments (run) #5 × Z02NLabAssignments (run) #6 ×
run:
***Welcome to the simple calculator***
Enter the first number: 1
Enter the second number: 2
Please select one of the following options
1 to Add
2 to Subtract
3 to Multiply
4 to Divide
Enter your choice: 4
The answer is 0.5
BUILD SUCCESSFUL (total time: 6 seconds)
Validation
Loop!
D
run:
Output - Z02NLabAssignments (run) # 7 X
IDD
D
run:
Enter the first number: 5
Enter the second number: 2
***Welcome to the simple calculator***
Enter the first number: 1234
Enter the second number: 567.89
Please select one of the following options
1 to Add
2 to Subtract
3 to Multiply
4 to Divide
Enter your choice: 3
The answer is 700776.26
BUILD SUCCESSFUL (total time: 15 seconds)
***Welcome to the simple calculator***
Please select one of the following options
1 to Add
2 to Subtract
3 to Multiply
4 to Divide
Enter your choice: 999
Please select one of the following options
1 to Add
2 to Subtract
3 to Multiply
4 to Divide
Enter your choice: -1
Please select one of the following options
1 to Add
2 to Subtract
3 to Multiply
4 to Divide
Enter your choice: 4
The answer is 2.5
BUILD SUCCESSFUL (total time: 32 seconds)
Transcribed Image Text:✰✰ D Your program should compile with no errors & make use of methods to earn full points. Hint: The 4 methods calcSum, calcSub, calcMul, calcDiv are essentially the same method with very minor changes needed! Z02NLabAssignments (run) #5 × Z02NLabAssignments (run) #6 × run: ***Welcome to the simple calculator*** Enter the first number: 1 Enter the second number: 2 Please select one of the following options 1 to Add 2 to Subtract 3 to Multiply 4 to Divide Enter your choice: 4 The answer is 0.5 BUILD SUCCESSFUL (total time: 6 seconds) Validation Loop! D run: Output - Z02NLabAssignments (run) # 7 X IDD D run: Enter the first number: 5 Enter the second number: 2 ***Welcome to the simple calculator*** Enter the first number: 1234 Enter the second number: 567.89 Please select one of the following options 1 to Add 2 to Subtract 3 to Multiply 4 to Divide Enter your choice: 3 The answer is 700776.26 BUILD SUCCESSFUL (total time: 15 seconds) ***Welcome to the simple calculator*** Please select one of the following options 1 to Add 2 to Subtract 3 to Multiply 4 to Divide Enter your choice: 999 Please select one of the following options 1 to Add 2 to Subtract 3 to Multiply 4 to Divide Enter your choice: -1 Please select one of the following options 1 to Add 2 to Subtract 3 to Multiply 4 to Divide Enter your choice: 4 The answer is 2.5 BUILD SUCCESSFUL (total time: 32 seconds)
Expert Solution
steps

Step by step

Solved in 3 steps

Blurred answer
Knowledge Booster
Function Arguments
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
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