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

  Recursive factorial program

Write a class Array that encapsulates an array and provides bounds-checked access. Create a recursive factorial program that prompts the user for an integer N and writes out a series of equations representing the calculation of N!.

  Hunt the wumpus game

Reprot on Hunt the Wumpus Game has Source Code listing, screen captures and UML design here and also, may include Javadoc source here.

  Create a gui interface

Create GUI Interface in java programing with these function: Sort by last name and print all employees info, Sort by job title and print all employees info, Sort by weekly salary and print all employees info, search by job title and print that emp..

  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.

  Write a university grading system in java

University grading system maintains number of tables to store, retrieve and manipulate student marks. Write a JAVA program that would simulate a number of cars.

  Wolves and sheep: design a game

This project is designed a game in java. you choose whether you'd like to write a wolf or a sheep agent. Then, you are assigned to either a "sheep" or a "wolf" team.

  Build a graphical user interface for displaying the image

Build a graphical user interface for displaying the image groups (= cluster) in JMJRST. Design and implement using a Swing interface.

  Determine the day of the week for new year''s day

This assignment contains a java project. Project evaluates the day of the week for New Year's Day.

  Write a java windowed application

Write a Java windowed application to do online quiz on general knowledge and the application also displays the quiz result.

  Input pairs of natural numbers

Java program to input pairs of natural numbers.

  Create classes implement java interface

Interface that contains a generic type. Create two classes that implement this interface.

  Java class, array, link list , generic class

These 14 questions covers java class, Array, link list , generic class.

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