Question: This question won't take you more than 15 mins. you will use an ArrayList as the backing store for a good and proper Stack implementation.
This question won't take you more than 15 mins.
you will use an ArrayList as the backing store for a good and proper Stack implementation. You will note that I gave the methods the names used EVERYWHERE ELSE IN THE WORLD (and removed many of the others) so that this class is a proper stack. Implement the push(), pop(), and peek() methods for efficient execution using an ArrayList backing store. Since you can use the ArrayList to do much of the work, you must also write a class of JUnit test methods provide 100% coverage of your methods.
----------------------------
code
package edu.buffalo.cse116; import java.util.ArrayList; import java.util.EmptyStackException; /** * Class which wraps Java's built-in {@link ArrayList} implementation so that it adds & removes elements from the end of * the List to improve efficiency AND uses the traditional method names. * * @author Matthew Hertz * @param Type of data stored within this Stack. */ public class ProperStack { /** * The actual Stack in which all the elements will be stored. This is protected (and not private) so that students can * use this field in the test cases they create.. */ protected ArrayList store; /** Create a new (empty) instance of this class. */ public ProperStack() { store = new ArrayList<>(); } /** * Adds an item to the end of the stack. Traditionally, this is the only method available to add data to a Stack. * * @param item Element to be added to the end of the stack. * @return Element added to the Stack (e.g., {@code item}). */ public E push(E item) { } /** * Removes and returns the element at the top of this Stack. Traditionally, this is the only method available to * remove data from the Stack. * * @return Element that was removed from the top of the Stack. * @throws EmptyStackException Thrown when the Stack does not have any elements to remove. */ public E pop() { } /** * Like {@link #pop()}, this returns the element at the top of the Stack, but unlike {@link #pop} this method DOES NOT * remove the element. * * @return Element that is at the top of the Stack. */ public E peek() { } } Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
