Part 1 Create and use a stack ADT (Abstract Data Type) to be used with a simple
ID: 3717443 • Letter: P
Question
Part 1
Create and use a stack ADT (Abstract Data Type) to be used with a simple calculator.
The calculator will be capable of evaluating the following simple expression:
2.3 * 1.2 + 14.0
The operators for the simple calculator are as followed:
Addition – ‘+’
Subtraction – ‘-‘
Multiplication – ‘*’
Division – ‘/’
This task involves three classes but just focus on the stack class please since I have to submit this question in two separate parts: Stack, Calculator, Driver. The driver class is complete and should not be modified. The other two classes are provided in incomplete format so they should be modified. You must fill in the details to make the class complete and for the driver to process correctly.
For the Stack class, you will need to complete:
top()
pop()
push()
isEmpty()
size()
Only the bodies of these 5 methods need to be completed.
Only include Stack.java work & down low is a driver class for reference if needed
import java.io.BufferedReader;
Stack.java file
public class Stack<E> {
If this is still too much please explain why in a comment because this is my 5th time reposting this question and I need help on this problem before my final grade is submitted.
Explanation / Answer
public class Stack { // Instance variables E stack[]; int top; int capacity; private final static int DEFAULT_SIZE = 30; // Constructors public Stack () { this(DEFAULT_SIZE); } public Stack (int capacity) { stack = (E[]) new Object[capacity]; this.top = -1; this.capacity = capacity; } // Other methods // Complete these methods for the assignment /** * Pushes an object on to the stack ** @param obj the object to be pushed */ public void push (E obj) { // Begin: Insert your code here to complete the method if(size()