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

  Boolean functions

Simplify the following Boolean functions, using 3-variable maps: F (x,y,z) = Σ(0,2,6,7)

  Evaluating the code

Which of the following best explains the situation after Line 1 has been executed? pCdoesnothaveatarget, and pCdoesnothaveaknownvalue. pCdoesnothaveatarget, butpCdoeshaveaknownvalue.

  Security issues while users processing the database

Describe the security issues which may be encountered when the multiple users process the database concurrently.

  Write down a user-defined function

Write down a user-defined function

  Explain the type of protocol you would use in this situation

Your company has a network that contains several NetWare 4.11 servers and uses IPX as the routing protocol. Each of the network segments has minimum one NetWare server on it. Which of the following responds to a Get Nearest Server (GNS)request from..

  Describe how logical and physical representations

explain how logical and physical representations of a To-Be system will differ.

  Problem on network design

You're asked to design a network for use in the training environment. It should be mobile, easy to set up, and simple to tear down. Speed is not an issue. Develop the network design that accommodates these requirements and keeps costs down.

  Write down a program that includes a function picnic()

The passed floating-point number represents TOTAL amount of money to be spent on food. The function is to determine the quantity of HOTDOGS, HAMBURGERS,SALAD,PICKLES that can be purchaced, writing these values directly into the respective variable..

  Implementing the nested – loop join algorithm

Implement the Nested – Loop Join algorithm in any of the programming language.The solution should involve:a) Source file of application,

  What are race situations difficult to debug

assume the legislature in your state is debating the adoption of UCITA and you have been known as an expert witness. What are the three most important ideas you want your legislators to get from the testimony.

  Program to implement the calculations

Write down a program which has a function named presentValue which carry out this calculation. The function must accept future value, annual interest rate, and number of the years as arguments.

  Developing a monthly budget structure

Write down a program which declares a MonthlyBudget structure with the member variables in order to hold each of these expense categories.

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