Design an algorithm for implementing a simple calculator. We first prompt the user for two numbers...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
Design an algorithm for implementing a simple calculator. We first prompt the user for two numbers on which they want to perform a calculation, and then the operation they want to perform. The user enters either the words ADD, SUBTRACT, MULTIPLY, DIVIDE, REMAINDER, or EXPONENT, or the symbol for the operation (+,-, *, /, %, ^). Perform the calculations based on the inputs entered by the user and display the result. Save your work into your external document (Assignment2.docx). Part 2: Convert the above algorithm into a Java program (SimpleCalculator.java). You can use a switch statement to determine the selected operation and case constants for each possible operation. Here are some sample runs: Welcome to my Simple Calculator You can perform the following Operations. Please type: ADD or for addition Note: SUBTRACT or - for subtraction MULTIPLY or for multiplication Let's Start. Enter the first operand: 5.5 Enter the second operand: 6.33 Enter your selection: SUBTRACT The result of subtracting 6.33 from 5.5 is -0.83 DIVIDE or for division REMAINDER or % for remainder EXPONENT or for exponentiation Welcome to my Simple Calculator You can perform the following Operations. Please type: ADD or for addition SUBTRACT or - for subtraction MULTIPLY or* for multiplication DIVIDE or for division REMAINDER or % for remainder EXPONENT or for exponentiation Let's Start. Enter the first operand: 8 Enter the second operand: 0 Enter your selection: / Dividing by e is not allowed Before performing division, you must check whether the divisor is 0 (compare its value to 0.0). If it is 0.0, print an error message; otherwise, perform the division. Test your program with different inputs. Design an algorithm for implementing a simple calculator. We first prompt the user for two numbers on which they want to perform a calculation, and then the operation they want to perform. The user enters either the words ADD, SUBTRACT, MULTIPLY, DIVIDE, REMAINDER, or EXPONENT, or the symbol for the operation (+,-, *, /, %, ^). Perform the calculations based on the inputs entered by the user and display the result. Save your work into your external document (Assignment2.docx). Part 2: Convert the above algorithm into a Java program (SimpleCalculator.java). You can use a switch statement to determine the selected operation and case constants for each possible operation. Here are some sample runs: Welcome to my Simple Calculator You can perform the following Operations. Please type: ADD or for addition Note: SUBTRACT or - for subtraction MULTIPLY or for multiplication Let's Start. Enter the first operand: 5.5 Enter the second operand: 6.33 Enter your selection: SUBTRACT The result of subtracting 6.33 from 5.5 is -0.83 DIVIDE or for division REMAINDER or % for remainder EXPONENT or for exponentiation Welcome to my Simple Calculator You can perform the following Operations. Please type: ADD or for addition SUBTRACT or - for subtraction MULTIPLY or* for multiplication DIVIDE or for division REMAINDER or % for remainder EXPONENT or for exponentiation Let's Start. Enter the first operand: 8 Enter the second operand: 0 Enter your selection: / Dividing by e is not allowed Before performing division, you must check whether the divisor is 0 (compare its value to 0.0). If it is 0.0, print an error message; otherwise, perform the division. Test your program with different inputs.
Expert Answer:
Answer rating: 100% (QA)
Simple Calculator Algorithm and Java Program Algorithm 1 Input Prompt the user to enter the first operand Read the first operand as a double Prompt the user to enter the second ... View the full answer
Related Book For
Introduction to Algorithms
ISBN: 978-0262033848
3rd edition
Authors: Thomas H. Cormen, Charles E. Leiserson, Ronald L. Rivest
Posted Date:
Students also viewed these programming questions
-
Consider your everyday life - work, family, school, etc. How do you think feedback affects learning in real-world applications? Now, consider feedback in terms of the criminal justice system and...
-
2. List the areas of the curriculum for your State/Territory (or the Australian curriculum, if you wish) and identify which area/s you most enjoyed at school and which area/s you found less enjoyable...
-
List three specific parts of the Case Guide, Objectives and Strategy Section (See below) that you had the most difficulty understanding. Describe your current understanding of these parts. Provide...
-
When a manager greets department visitors or attends ceremonies, he or she is playing the role of: Figurehead Conceptual Empowerment Productivity
-
Use the graph of the function f(x) = 1 / (1 + e1/x) to state the value of each limit, if it exists. If it does not exist, explain why. (a) limx0 f (x) (b) limx0+ f (x) (c) limx0 f (x)
-
A review of emergency room records at rural Millard Fell more Memorial Hospital was performed to determine the probability distribution of the number of patients entering the emergency room during a...
-
In a certain application, a pump is required to deliver \(5000 \mathrm{gpm}\) against a \(300-\mathrm{ft}\) head when operating at \(1200 \mathrm{rpm}\). What type of pump would you recommend?
-
Gheorghe Moresan Lumber Company handles three principal lines of merchandise with these varying rates of gross profit on cost. Lumber ......... 25% Millwork ........ 30% Hardware and fittings .. 40%...
-
In your answers, you should make references to support your answers by informal pinpoint citation to book and page number within parentheses. For example: Computer Crime Law at p. __. You do not need...
-
In the investment world, commodities are typically pretty boring. From livestock to grains to steel and other metals, commodities have their ups and downs. But long term, the world will always need...
-
You are considering taking out a loan from the so-called "Tiger B. Shark" finance company. The company's leaflet states that the loan you plan to take will be settled on a "four-for-five weekly basis...
-
How do sociological theories of deviance explain the complex relationship between societal norms and individual behavior, and to what extent do these theories consider the influence of power dynamics...
-
Vector A has a magnitude of 8 . 0 0 units, vector vector B has a magnitude of 9 . 0 0 units, and the dot product A B has a value of 6 7 . What is the angle between the directions of A and vector B ?
-
1. The Investment Industry Regulatory Organization of Canada (IIROC) will issue a notice of application to announce that a settlement hearing will be held before a Hearing Panel (the Hearing Panel)...
-
4. The equilibrium rate of return is 8 percent for this particular security. For all securities, the inflation risk premium is 1.25 percent and the real risk-free rate is 3.5 percent. The security's...
-
J.M. Smucker included the following information in its April 2019 10-K. $ millions Apr. 30, 2019 Apr. 30, 2018 Sales $7,994.8 Depreciation expense 210.1 Land 124.5 $122.5 Buildings and fixtures...
-
The function f(x) = x is a probability density function over the interval [0, b]. What is b? given function what is also the function of probability density over interval [0,b]. How to find b?
-
Determine by direct integration the values of x for the two volumes obtained by passing a vertical cutting plane through the given shape of Fig. 5.21. The cutting plane is parallel to the base of the...
-
Argue that for any constant 0 < 1/2, the probability is approximately 1 - 2 that on a random input array, PARTITION produces a split more balanced than 1 to .
-
Let A k denote the kth leading submatrix of a symmetric positive-definite matrix A. Prove that det (Ak)/ det(A k - 1 ) is the kth pivot during LU decomposition, where, by convention, det(A) = 1.
-
Give a bijection from to .
-
Describe the equitable parent doctrine and explain how it was applied by the Wisconsin Supreme Court in Ay val.
-
Explain what it means to disestablish paternity. Identify some of the common arguments in favor of and against disestablishment.
-
Identify three circumstances in which assisted reproductive technology is most likely to be utilized as a reproductive option.
Study smarter with the SolutionInn App