Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

MUST BE DONE IN NETBEANS JAVA 5. (20 points) ArrayStack class represents array implementation of the Stack. Provided class has four methods that are not

image text in transcribedimage text in transcribed

MUST BE DONE IN NETBEANS JAVA

5. (20 points) ArrayStack class represents array implementation of the Stack. Provided class has four methods that are not implemented: push(T newEntry), peek(), clear() and pop(). Complete the implementation of these methods. /** Task: Retrieves the stack's top entry. * @return either the object at the top of the stack or null if * the stack is empty */ public T peek() { public class ArrayStack implements Stackinterface { private T[] stack; // array of stack entries private int toplndex; // index of top entry private boolean initialized = false; private static final int DEFAULT_INITIAL_CAPACITY = 50; private static final int MAX_CAPACITY = 10000; } /** Task: Removes all entries from the stack */ public void clear() { public ArrayStack() { this(DEFAULT_INITIAL_CAPACITY); } } public ArrayStack(int initialCapacity) { checkCapacity(initialCapacity); @ SuppressWarnings("unchecked") T[] tempStack = (T[])new Object[initialCapacity]; stack = tempStack; toplndex = -1; initialized = true; } // end constructor //adds a new entry to the top of the stack public void push(T newEntry) { public void ensureCapacity(){ if (toplndex == stack.length-1) {// if array is full, expand array int newLength = 2 * stack.length; checkCapacity(newLength); Arrays.copyOf(stack, newLength); } } //check if there is enough capacity, if not throw an exception public void checkCapacity(int capacityLength) { if (MAX_CAPACITY

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

Step: 3

blur-text-image

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

Hands On Database

Authors: Steve Conger

1st Edition

013610827X, 978-0136108276

More Books

Students also viewed these Databases questions

Question

Explain consumer behaviour.

Answered: 1 week ago

Question

Explain the factors influencing consumer behaviour.

Answered: 1 week ago

Question

What is Change Control and how does it operate?

Answered: 1 week ago

Question

How do Data Requirements relate to Functional Requirements?

Answered: 1 week ago