Question
Design a simple calculator (class Calculator) by using the Stack ADT: a. This calculator accepts single () (no nested parenthesis) and +/ operators only. b.
Design a simple calculator (class Calculator) by using the Stack ADT: a. This calculator accepts single () (no nested parenthesis) and +/ operators only. b. This calculator reads the input as a string literal. c. For example: input: 1 + 3 (21 + 7) + 12 6 + (9 + 3) 11 output: 17
writting in java
** Note: cannot use import Java.util.Stack **
/*following the following stack interface*/
/** * A collection of objects that are inserted and removed according to the last-in * first-out principle. Although similar in purpose, this interface differs from * java.util.Stack */
public interface Stack {
/**method: size * returns the number of elements in the stack * @return number of elements in the stack */ int size();
/**method: isEmpty * tests whether the stack is empty * @return true if the stack is empty, false otherwise */ boolean isEmpty();
/**method: top * returns, but does not remove, the element at the top of the stack * @return top element in the stack (or null if empty) */ T top(); /**method: push * inserts an element at the top of the stack * @param e the element to be inserted */ void push(T e);
/**method: pop * Removes and returns the top element from the stack * @return element removed (or null if empty) */ T pop();
}
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