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

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!