Problem

Visit www.myprogramminglab.com to complete select exercises online and get instant feedbac...

Visit www.myprogramminglab.com to complete select exercises online and get instant feedback.

Exercise

Write a program that can serve as a simple calculator. This calculator keeps track of a single number (of type double) that is called result and that starts out as 0.0. Each cycle allows the user to repeatedly add, subtract, multiply, or divide by a second number. The result of one of these operations becomes the new value of result. The calculation ends when the user enters the letter R for “result” (either in upper-or lowercase). The user is allowed to do another calculation from the beginning as often as desired.

The input format is shown in the following sample dialogue. If the user enters any operator symbol other than +, −, *, or /, then an UnknownOperatorException is thrown and the user is asked to reenter that line of input. Defining the class UnknownOperatorException is part of this project.

Calculator is on.result = 0.0+ 5result + 5.0 = 5.0new result = 5.0* 2.2result * 2.2 = 11.0updated result = 11.0% 10% is an unknown operation. Reenter, your last line:* 0.1result * 0.1 = 1.1updated result = 1.1rFinal result = 1.1Rgain? (y/n)yesresult = 0.0+10Result + 10.0 = 10.0 Rew result = 10.0/2result / 2.0 = 5.0updated result = 5.0rFinal result = 5.0 Ugain? (y/n)NEnd of Program

Step-by-Step Solution

Request Professional Solution

Request Solution!

We need at least 10 more requests to produce the solution.

0 / 10 have requested this problem solution

The more requests, the faster the answer.

Request! (Login Required)


All students who have requested the solution will be notified once they are available.
Add your Solution
Textbook Solutions and Answers Search
Solutions For Problems in Chapter 9