Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

The digit method takes the digit input parameter and appends it to the operand variable. Then the method returns the digit. Compile and run the

image text in transcribed

The digit method takes the digit input parameter and appends it to the operand variable. Then the method returns the digit. Compile and run the application. Confirm by clicking on each number 0 through 9 appears in the text area. -

The clearEntry method resets the operand back to the empty string. Return the string that is shown when you run the CalcRPN.jar application and perform the same action. -

The addDecimal method adds a decimal point to the operand. Then it returns the period character. This method needs to be handled carefully because only one decimal is allowed in an operand. Use the String method contains to help you here. -

The enterPressed method pushes a non-blank operand (converted to a Float) onto the results Stack. (If the operand is blank, simply return a blank string). You can use Float.parseFloat to convert a String object to a Float object. The operand must be reset to an empty string. You can return a single space.

The clear method clears the results Stack and the operand. -

The operator method performs the calculation work as determined by the type of operator it is passed. First the method pushes the operand value onto the results Stack if that operand is non-blank (and then resets operand blank). Then the method returns an empty string if the results Stack has less than two elements in it (use the Stacks size method) because there is no point in performing any calculations if the Stack has only one or fewer elements. Assuming the results Stack has at least two values, pop them into two new Float variables, a and b. Declare a third Float variable c and initialize it to Float(0). The c variable serves as the calculated sum, difference, product, etc (e.g. c = a + b). Use a switch statement on the op parameter to determine which operator type is required. (e.g. case +:). You need to push the c value back onto the results Stack and then return the string form of the c variable. The exponent (^) operator will require use of the Math.pow function and the doubleValue() function to convert Float objects into double values.

package calcrpn; 1 2 3 import java.util.Stack; 4 5 public class CalcBrain implements CalcRPNOperations { 7 Stack results; String operand; 8 9 10 2 12 13 public CalcBrain() { results = new Stack(); operand } package calcrpn; 1 2 3 import java.util.Stack; 4 5 public class CalcBrain implements CalcRPNOperations { 7 Stack results; String operand; 8 9 10 2 12 13 public CalcBrain() { results = new Stack(); operand }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Beginning C# 2005 Databases

Authors: Karli Watson

1st Edition

0470044063, 978-0470044063

More Books

Students also viewed these Databases questions

Question

=+ How well do you think you could do your job?

Answered: 1 week ago