Answered step by step
Verified Expert Solution
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
And following these specifications:
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 itStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started