Question
Create an application that simulates an old-school stack calculator that uses Reverse Polish Notation (RPN). Example Console Display Welcome to the Stack Calculator. Commands: push
Create an application that simulates an old-school stack calculator that uses Reverse Polish Notation (RPN).
Example Console Display
Welcome to the Stack Calculator.
Commands: push n, add, sub, mult, div, clear, or quit.
stack> push 4
4.0
stack> push 3
3.0
4.0
stack> push 2
2.0
3.0
4.0
stack> mult
6.0
4.0
stack> add
10.0
stack> clear
empty
stack> quit
Thanks for using the Stack Calculator.
Specifications
- The calculator should be implemented as a separate class named StackCalculator. This class should have the following methods:
Method Explanation
public void push(double x) Pushes x onto the top of the stack.
public double pop() Removes the value from the top of the stack.
public double add() Removes two values from the stack, adds them, and pushes the result back onto the stack.
public double subtract() Same as add() but subtracts the values.
public double multiply() Same as add() but multiplies the values.
public double divide() Same as add() but divides the values.
public void clear() Removes all entries from the stack.
public double[] getValues() Returns all of the values from the stack in an array without removing them from the stack.
public int size() Gets the number of values in the stack.
- The StackCalculator class should use a linked list to maintain the stack data.
- Add code to another class that uses the StackCalculator class. This class should contain the following static methods in addition to the main method: displayPrompt(), listValues(), and performCalculation(String command).
- Be sure to test all the methods in the StackCalculator. I will.
-
Use proper statement indentation and meaningful variable names in the code.
- Add a comment to each code statement explaining why the statement is in the code.
- Add javadoc comments to all the classes in the project. Make sure these comments include @param and @return tags where ever these tags are appropriate (see pages 336 -339).
- Add a Javadoc multi-line comment with a description of this application (to include your name and the date written) at the beginning of the code.
- This documentation must also include descriptions for all of the constructors and methods as well as the information about all parameters and return values.
- Generate the documentation for the entire project (see pages 340 - 341).
- View the documentation to be sure it is complete and be sure it is contained in the project file that you submit.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started