Question
Create a Calculator class that implements the provided StackCalculator interface. Java program must use the signature and follow each of the requirements. Thanks in advance
Create a Calculator class that implements the provided StackCalculator interface. Java program must use the signature and follow each of the requirements. Thanks in advance
Feature | Signature | Requirement |
Constructor | Calculator() | Precondition: none Postcondition: a new calculator with an empty number stack |
Methods | public void enter(String entry) | Precondition: entry is either a double value a recognized operator [ +, -, *, /] Postcondition: if the entry is a double, the value is pushed onto the calculators number stack. If an operator, the top two values are popped from the stack, the operation performed, and the result pushed onto the stack. Note: the second operand is popped first. |
| double peek() | Precondition: number stack is not empty, otherwise throws EmptyStackException Looks at the number at the top of this stack without removing it from the stack. |
| double pop() | Precondition: number stack is not empty, otherwise throws EmptyStackException Removes the number at the top of this stack and returns that value. |
| void clear() | Removes all numbers from this stack. The stack will be empty after this call returns |
| boolean isEmpty | Tests If the number stack of this calculator is empty |
| int size() | Returns the number of values in this calculators number stack. |
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