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

  Data structures and algorithms

Code analysis and programming.

  Class pointparameters

What is the output of the following Java program? Explain in terms of how parameters are passed in Java.import java.awt.*;class PointParameters

  Plot pois on a graph

Write a JAVA program that would get the locations of all the POIs from the file and plot them on a map.

  Specify, design, and implement a class

Specify, design, and implement a class that can be used in a program that simulates a combination lock. The lock has a circular knob with the numbers 0 through 39 marked on the edge, and it has a three-number combination, which we will call x,y,z.

  Calculate the premium and multiply the value of the object

Implement all the four Java classes described with the correct inheritance of abstract classes. Calculate the premium and multiply the value of the object being insured by the corresponding RATE. See the RATE tables above.

  Write a program deal that takes an integer and prints

Write a program Deal that takes an integer, save it in "kHands" from the keyboard and prints kHands poker hands (five cards each hand) from a shuffled deck, separated by blank lines Screenshot of the program and hands.

  Write program that reverses string with the in main function

Write a program that reverses a string with the In themain function, ask the user to enter a string and The entered string can be handled as C-string (or converted to C-string).

  Problem 1write a java class called problem1 implement the

problem 1write a java class called problem1. implement the following method in your classpublic static int

  Create a java class named headphones

1. Create a Java class named HeadPhones to represent a headphone set. The class contains:

  Programing of tree java

The listing of Tree.java is supplied below as a starting point for this lab. A picture of Tree.java output is also shown. Either cut/paste the code or type it in. Run the program to verify that it works. Study the listing until you understand comp..

  Java shape program console

Program is adequately documented. It's comments identifies its name, purpose, author and date.Throughout the code, comments and/or relevant component names should attempt to make theprogram understandable.

  Design and implement a set of classes and interfaces and

design and implement a set of classes and interfaces and use them to evaluate the rtas resource requirements.nbspyour

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