Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I need an expert to write me in the main to test the application JAVA programming import java.util.Arrays; interface MyStack { public void push(T o);

I need an expert to write me in the main to test the application JAVA programming

import java.util.Arrays; interface MyStack{ public void push(T o); public T pop() throws StackEmptyException; public T peek(); public boolean isEmpty(); public int size(); }

MyArrayStack implements MyStack{ private static final int DEFAULT_STACK_SIZE = 100; T[] stackArray; int top = 0; public MyArrayStack(){ this(DEFAULT_STACK_SIZE); } public MyArrayStack(int defaultSize){ top = 0; stackArray = (T[]) new Object[defaultSize]; } public void push(T o){ if(size() == stackArray.length) expandCapacity(; stackArray[top] = o; top++ } private void expandCapacity(){ stackArray = Array.copyOf(stackArray, stackArray.length*2); System.out.println("stackArray size is automatically expanded: "+stackArray.length) } public T pop() throws StackEmptyException { if (isEmpty()) throw new StackEmptyException("Stack is empty"); top--; T o = stackArray[top]; stackArray[top] = null; return o; }

public T peek() { if (isEmpty()) return null; return stackArray[top-1]; } public boolean isEmpty(){ if(top == 0) return true; return false; } public int size(){ return top; } }

public class Main { public static void main(String[] args) { //Write Test application to run the MyArrayStack class. } }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Data Analysis Using SQL And Excel

Authors: Gordon S Linoff

2nd Edition

111902143X, 9781119021438

More Books

Students also viewed these Databases questions