Question: Implement a simple stack-based post-fix calculator. Your program should accept integer operands and the +, -, and * operators. Expressions should be entered one item

Implement a simple stack-based post-fix calculator. Your program should accept integer operands and the +, -, and * operators. Expressions should be entered one item per line with = on the final line to trigger the calculation and output of the result. Your program should detect invalid expressions (e.g., too few operands, too many operands).

Here is the Stack class that was created use this for implementation

public class Stack { private final int SIZE =99; private int top; private int arr[]; public Stack() { top = -1; arr = new int[SIZE]; } // implement various stack methods public void push(int val) { if (top == SIZE) { System.out.println("Stack is full"); } else { top++; arr[top] = val; } } public int pop() { // check of stack is empty or not if (top == -1) { System.out.println("Stack is empty"); return -1; } else { top--; return arr[top + 1]; } } public int top() { // check of stack is empty or not if (top == -1) { System.out.println("Stack is empty"); return -1; } else { return arr[top]; } } public int size() { return top + 1; } public boolean isEmpty() { // check of stack is empty or not if (top == -1) { return true; } else { return false; } } public boolean isFull() { // check of stack is full or not if (top == SIZE) { return true; } else { return false; } } // main driver code of the program. contains test code public static void main(String args[]) { // create Stack Stack s = new Stack(); // push some values s.push(10); s.push(20); System.out.println("Stack size : " + s.size()); System.out.println("Stack top elem : " + s.top()); System.out.println("Stack is empty ? : " + s.isEmpty()); s.pop(); System.out.println("Stack top elem : " + s.top()); s.pop(); System.out.println("Stack size : " + s.size()); System.out.println("Stack is empty ? : " + s.isEmpty()); } }

Use the array based stack class above for implementation required in the question thank you!!!

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!