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)

EBK JAVA PROGRAMMING
8th Edition
ISBN:9781305480537
Author:FARRELL
Publisher:FARRELL
Chapter2: Using Data
Section: Chapter Questions
Problem 12PE
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
EBK JAVA PROGRAMMING
EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781305480537
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT
EBK JAVA PROGRAMMING
EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781337671385
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT
C++ Programming: From Problem Analysis to Program…
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning
Microsoft Visual C#
Microsoft Visual C#
Computer Science
ISBN:
9781337102100
Author:
Joyce, Farrell.
Publisher:
Cengage Learning,