Write a postfixcalculator class

Assignment Help JAVA Programming
Reference no: EM131588955

Write a PostfixCalculator class.

1. You should have two private member variables in this class
- A stack of double operand
- A map of strings to operator objects. (something like
private Map<String, Operator>operatorMap;)

2. The constructor should fill the operator map with associations of symbols to operator objects as described in the table below. You will have to create multiple implementations of the operator interface in order to do this.
- The Operator implementations should be nested inside the PostfixCalculator class. It is up to you if you make them static nested classes, non-static inner classes, local classes, or anonymous classes, but they must all be inside PostfixCalculator somehow.

3. The storeOperand method takes a double and pushes it onto the operand stack. It does not return anything.

4. The evalOperator method takes an operator string, looks up the corresponding operator object in the operator map, pops the appropriate number of operands (as given by the numArgs method) and places them into a list, evaluates the operator with the operands in the list, and pushes the result onto the operand stack. It does not return anything, but operators may have side effects, such as printing the argument to standard output.

Operators
Your calculator should recognize the following operators. Note that there can be more than one symbol for a given operation. (For example, 1 2 + would have the same result as 1 2 add)

Name

Symbol

# Arguments

Result

addition

+ add

2

Sum of arguments A B + → A+B

subtraction

- sub

2

Difference of arguments A B - → A-B

multiplication

* mult

2

Product of arguments

division

/ div

2

Quotient of arguments

print

= print

1

Print argument to standard out and return argument

Test Input
1 =
2 print
3 2 + =
3 2 add =
3 2 - =
3 2 sub =
3 2 * =
3 2 mult =
3 2 / =
3 2 div =
1 2 3 * + 4 - =
5 1 2 + 4 * + 3 - =
1 2 + 3 * 6 + 2 3 + / =
10 = 12 = / = 35 = + = 16 = - = 23 = * = 37 = + =

Test output
1.0
2.0
5.0
5.0
1.0
1.0
6.0
6.0
1.5
1.5
3.0
14.0
3.0
10.0
12.0
0.8333333333333334
35.0
35.833333333333336
16.0
19.833333333333336
23.0
456.16666666666674
37.0
493.16666666666674

Attachment:- Java code.rar

Reference no: EM131588955

Questions Cloud

Explain the impact both of these issues have on social order : Examine at least two (2) issues facing law enforcement today and explain the impact both of these issues have on social order.
The future of us healthcare by barry bittman : He concludes his presentation with the declaration that if we follow his suggestions, our health care system will not only survive
What motivates you as a consumer to purchase certain product : What motivates you as a consumer to purchase certain products? What are some of the factors that influence buyer behavior? Provide an example.
What is the concept of overwhelming circumstantial evidence : What are two methods of demonstrative evidence used to clarify the issues surrounding actions or lack of actions at a crime scene for a judge or jury? Explain.
Write a postfixcalculator class : Write a PostfixCalculator class - create multiple implementations of the operator interface in order to do this - You should have two private member variables
Create a brief portrait of the ideal customer : Create a brief portrait of the ideal customer. Generate a positioning statement for the organization with consideration for the brand and strategy.
The best practices in hazard mitigation : Do any of the examples described in your readings exist in your community, neighborhood, or home? Explain your answer.
Lower gasoline prices for consumers : However, some economists have argued that Rich's scheme actually resulted in lower gasoline prices for consumers.
Discuss the justifications for the terrorism : Select one of the historical evolutionary periods of terrorism discussed this week (i.e. French Revolution to the anarchism concept originating in ancient.

Reviews

Write a Review

JAVA Programming Questions & Answers

  Java application that prompts a user for a full name address

Write a Java application that prompts a user for a full name and street address and constructs an ID from the user's initials and numeric part of the address. For example, the user William Henry Harrison who lives at 34 elm would have an ID of WHH..

  Creating a switch-case statement

Creating a switch-case Statement - Propagating and Catching an Exception - Create a method called reverse - Create an enclosing class called MyException

  Java application that reads a date in numeric form

Designand write a java application that reads a date in numeric form from a set of three fields and displays it in English within a label. Use appropriate buttons. For Example:

  Write prolog clauses to express therelationships

Write prolog clauses to express the following relationships, given the parent relationship: grand-parent, sibling, cousin.

  Company infrastructure and the identification

Your CEO meets with you and assigns you the following tasks, to be assembled in a written report to the CEO:  The review of the company's infrastructure and the identification of all types of vulnerabilities -- environmental, physical, an..

  Sets a loop to find 10 random generated

Write a java code that 1) uploads a file 2) sets a loop to find 10 random generated words from the file and then search those words by a. IndexSequential Method b. indexBinary Method. then, report how much time both methods took.

  Methods and best practices for conducting a code review

Use the information in the web article Effective Code Reviews Without the Pain for methods and best practices for conducting a code review, and tips for conducting the review remotely

  Create a world class that contains a 2d array

You have to create a world class that contains a 2d array then create an abstract class called organism that contains move() method the organism should move randomly one step at the time.

  Default and parameterized constructors

Create a class Count with a data member current_count with proper access specifier. Create another tester class (which has main method) to instantiate two counters of Count class.

  Java program that iterates through the integers

Write a Java program that iterates through the integers from 1 to 20, computing the square of each number and writing the information to a file called squares.txt.

  Create a class called point

Create a class called Point that has the following private members: float x - the x-coordinate of the point. float y - the y-coordinate of the point

  Modeling the caves

Assignment 2 Description:  You are a mighty warrior, and armed with your trusty bow and 3 arrows, you enter The Caves in search of the mighty Wumpus. If you shoot the Wumpus, you are victorious and the masses will praise you, but if you stumble upon ..

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