Write java program that can serve as simple calculator

Assignment Help Computer Engineering
Reference no: EM1329857

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: EM1329857

Questions Cloud

The key ingredients to success : What are the key ingredients to success in a Consignment Store?
Elements of the innovative process : Elements of the Innovative process - Write a paper in which you examine the elements of the innovative process as well as compare and contrast incremental
Assume if the inflation rate is this still acceptable : Assume if the inflation rate is 5percent is this still acceptable. Provide quantitative justification for your answer.
What is strategy formulation and execution : How has FedEx managed to maintain technical superiority (i.e., reliability, service, package tracking, etc.) in its industry? Can FedEx continue to do so in the future? Why or why not?
Write java program that can serve as simple calculator : Write down 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.
Elucidate what are some economic conditions : Elucidate what are some economic conditions that affect the cost of money
Elucidate whether current economic conditions are more : Elucidate whether current economic conditions are more consistent with the Keynesian or classical economic theories.
Practices around information management : What is the most challenging problems often encountered when implementing more effective processes and practices around information management?
Reading literature critical for researchers : Why is reading literature critical for researchers?

Reviews

Write a Review

Computer Engineering Questions & Answers

  How personal data can be an overwhelming task

If we are not able to protect our data, and data protection is left to the market, will data protection be possible only for the rich.

  Cashregister requires to support a method void undo()

imagine the CashRegister needs to support a method void undo() that undoes the addition of the preceding item. This enables a cashier to quickly undo a mistake. What instance variables should you add to the CashRegister class to support this modif..

  Benefit of ethical hacking

Describe what you consider is the main benefit of the ethical hacking be sure to involve what is the role of an ethical hacker.

  Performance improvement for the least amount of money

suppose in your computer, the most of your daytime processes spend 75 percent of their time running in the CPU and 25% waiting for service from disk.

  Create a compensation structure

Evaluates both approaches (job-based and person-based) and creates a compensation structure based on both approaches. In considering both approaches, what would the compensation structure look like for each position? Justify your recommendations w..

  Why compression algorithms are frequently used in forensics

why Compression algorithms are frequently used in forensics.how they can potentially affect evidence, paying particular attention to algorithms implemented by forensic tools. You need to be clear yet concise.

  Explain fast process of distributing the cards to accountant

Explain fast process of distributing the cards to accountant.

  What business applications may find roles useful

What business applications may find roles useful.

  Benefit and drawback of each major operating system

Benefit and drawback of each major operating system

  What are the business rules

What is 1 tier, 2 tiers and 3 tiers and N tiers in database architecture? could you offer an example on each tier.

  Network security planning

Securing a large internetwork is considered as a daunting challenge. Cloud computing and the social networks add to this complexity. In two to three (2-3) pages.

  Program to count the number of times page is opened

Generate a page in order to count the number of times the page is viewed by the user in a single session. Each time page is refreshed or opened in the browser during the session counts as 1 page view.

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