Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Using this format: package Main; import java.util.ArrayList; public class StackList{ // Fields private ArrayList a; // Declared object // Constructor public StackList(){ // TODO }

Using this format:

package Main; import java.util.ArrayList; public class StackList{ // Fields private ArrayList a; // Declared object // Constructor public StackList(){ // TODO } // Methods public void push(String item){ // TODO } public String pop(){ // TODO } public String peek(){ // TODO } public boolean isEmpty(){ // TODO } public int size(){ // TODO } public void clear(){ // TODO } }

And following these specifications:

image text in transcribedimage text in transcribed
Specications You must implement the following in the \"StackList.java\" le for full credit: public StackList() This is the constructor for the class. You must complete the body of this as needed to make the class do what it is supposed to do. public void push(String item) This should take the \"item\" String in the parameter and add this to our Stack. Since we are using an ArrayList behind the scenes to represent the stack, you must gure out how to store this item in the ArrayList. public String pOpll This should return the String at the top of the Stack. Then it should remove this String from the stack. You must gure out how to do this with the ArrayList behind the scenes. CAVEAT: You must do bounds checking! If your stack is empty, the pop must return the String "EMPTY\" (Failure to do this will crash the program and result in zero points for this lab!) public String peek() This should return the String at the top of the Stack. This does NOT remove the String from the stack but only return the String at the head of the stack. CAVEAT: You must do bounds checking! If your stack is empty, the peek must return the String "EMPTY\" ( Failure to do this will crash the program and result in zero points for this lab!) public boolean isEmptyl) This must return whether the stack is currentlv emptv or not. public int size() This must return how many items are on the stack. This must be a non-negative value. public void clear() This should empty the stack; regardless of the number of items in it

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

Financial management theory and practice

Authors: Eugene F. Brigham and Michael C. Ehrhardt

12th Edition

978-0030243998, 30243998, 324422695, 978-0324422696

Students also viewed these Programming questions

Question

1. Given her responsibilities, what type of salesperson is Ann?

Answered: 1 week ago