Write a java program that can serve as a simple calculator.

Assignment Help JAVA Programming
Reference no: EM13940750

Write a Java 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" or "r" for 'result'. 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. Define the class UnknownOperatorException appropriately.

Calculator is on
result = 0.0
+5
result + 5.0 = 5.0
new result = 5.0
*2.2
result * 2.2 = 11.0
updated result = 11.0
%10
% is an unknown operation.
Reenter, your last line:
*0.1
result * 0.1 = 1.1
updated result = 1.1
r
Final result = 1.1
Do you want calculate again? (y/n)
yes
result = 0.0
+10
result + 10.0 = 10.0
new result = 10.0
/2
result / 2.0 = 5.0
updated result = 5.0
R
Final result = 5.0
Do you want calculate again? (y/n)
N
End of Program

Reference no: EM13940750

Questions Cloud

Explore the resources and capabilitiestopic area : You need to explore the Resources and Capabilitiestopic area discussing theoretical concepts within the area and look at how Canon's strategy can be understood by drawing on ideas from the literature. You are of course permitted to draw on other a..
Unions tend to disavow their usefulness : While performance evaluations are part of most organizations, unions tend to disavow their usefulness. Are performance evaluations needed in a union environment?
Dealing with the blood diamonds issue : Evaluate DeBeers' choice of strategy in dealing with the blood diamonds issue (Hint:use the criteria of suitability, acceptability and feasibility (Johnson et al, 2011, p.364ff), bearing in mind that this was not simply a financial decision)
What are your reservations about staff reduction efforts : What are your reservations about staff reduction efforts? What can a manager, do to become more confident in facing reduction in workforce issues?
Write a java program that can serve as a simple calculator. : Write a Java 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.
Explain specifics about penalties that led to your opinion : Explain the specifics about the penalties that led to your opinion. In addition, explain whether you think most policies in the system have the goal of:- Using punishment or threat of punishment to deter people from committing crime.
Break-even chart to illustrate this solution : Each additional unit a company produces costs £45 to manufacture and it can sell each unit it produces for a fixed price of £72. The firm also has fixed costs of £8,100.
Show with a diagram the cash flows in this given deal : Show, with a diagram, the cash flows in this deal, assuming no Early Buyout Option. Would the deal make sense for DEF Leasing, assuming that its shareholders insist on a required return on equity of 15% p.a.
Steps in market research process : List the four steps in market research process? Describe in some detail the three types of research that are typically used in a business environment and any specify areas of research interest to business?

Reviews

Write a Review

JAVA Programming Questions & Answers

  Create a package called people

Create a second package called ‘task01'. Within this package provide classes which perform the following tasks.

  The continual rise in popularity of php as a solution

Question: With the continual rise in popularity of PHP as a solution to e-commerce applications and the tendency to protect intellectual property, just how open do you think the future will be as far as Web application development is concerned? For t..

  Price and quantity of an article

XYZ Supermarket wants a program that will prompt for the product code, pricing code, price and quantity of an article. Your program is then to calculate a discount rate according to the pricing code.

  Write java application to demonstrate the behavior

The source code is patterned after a similar example that was taken from Joyce Farrell's textbook, Java Programming.

  Determine values of the side of triangle

Enter 3 integers and determine if these 3 values make up the sides of a triangle. If any side is

  What are command line arguments in java

Modify the program such that if there are no command line arguments, when you type:

  Which allows to input a year and when hit the check button

Create a JAVA GUI (With Frame), which allows to input a year and when hit the check button, will show the picture of Chinese zodiac animal! I am trying to make a calculator: i have the method for or the calculation method to show how to calculate:

  Draw dashed lines

Write a class Lines containing a static method dashedLine to draw dashed lines, so it can write:

  Design and implement a java program to determine the sum

Design and implement a Java program that will gather a group of floating point numbers and determine the sum and average of the data entered. The program should use separate methods for inputting the data, calculating the sum, calculating the aver..

  Write a program that will process the data file

Write a program that will process the data file to read the file and calculate the number of assistants and the average salary and the number of associates and the average salary

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd