Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Lab-lmplement a Stack ADT as an Array Part #1: Practice with the Stack Design a Java class called StackArray, in StackArray.java. It should have three

image text in transcribed

Lab-lmplement a Stack ADT as an Array Part #1: Practice with the Stack Design a Java class called StackArray, in StackArray.java. It should have three data elements 1) Size (number of non-null items in the array - should be zero initially) 2) Capacity (initial size of the array four is a good number for this) 3) String array (initialize to the value of capacity in the constructor) Since it's based on the Stack abstract data type, it should have these methods One-argument constructor (capacity) - No-arg constructor Get methods for size, capacity and the array isEmptx) that returns true/false (whether array size is zero) Properly-formatted toString) method (with String return type) that prints isEmpty), the size and the array contents Push0 method that takes a String argument and adds the string to the array at index position given by the size (initially zero but increases by one each time). It should also call the toString) method so the user can see the current state of the Stack object. Pop) method that prints the item at the top of the stack, decrements the size by one and sets the previous last position to null. Should also call the toString) method Resize0) method that resizes the stack to double it's size + 1. Push0 should call resize0 if the size of the array equals capacity. Otherwise you will get AralodexQutQfoundsException. Include a main) method to test the object. Add several strings (e.g. "fourscore", "and", 'seven", Years", "ago") and then pop them off the stack. When it's run, you should be able to see the stack displayed as it grows and shrinks See next page for a sample run

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

Machine Learning And Knowledge Discovery In Databases European Conference Ecml Pkdd 2014 Nancy France September 15 19 2014 Proceedings Part 2 Lnai 8725

Authors: Toon Calders ,Floriana Esposito ,Eyke Hullermeier ,Rosa Meo

2014th Edition

3662448505, 978-3662448502

More Books

Students also viewed these Databases questions