Question: LinkedListStackTests.java ----------------------------------- import org.junit.jupiter.api.Test; import java.util.NoSuchElementException; import static org.junit.jupiter.api.Assertions.*; public class LinkedListStackTests { @Test void testPushPopValues() { LinkedListStack stack = new LinkedListStack(); for (int i

LinkedListStackTests.java
-----------------------------------
import org.junit.jupiter.api.Test; import java.util.NoSuchElementException; import static org.junit.jupiter.api.Assertions.*; public class LinkedListStackTests { @Test void testPushPopValues() { LinkedListStack stack = new LinkedListStack(); for (int i = 0; i stack = new LinkedListStack(); assertThrows(NoSuchElementException.class, () -> stack.pop()); } @Test void testSize() { LinkedListStack stack = new LinkedListStack(); for (int i = 0; i stackA = new LinkedListStack(); LinkedListStack stackB = new LinkedListStack(); for (int i = 0; i -------------------------------------
LinkedListStack.java
---------------------------------
import java.util.NoSuchElementException; public class LinkedListStack { // TODO: add fields private class Node { // TODO: add fields } public LinkedListStack() { // TODO } public void push(E e) { // TODO } public E pop() { // TODO return null; } public int size() { // TODO return -1; } @Override public boolean equals(Object obj) { if (obj instanceof LinkedListStack) { LinkedListStack other = (LinkedListStack)obj; // Extra credit: Check if this and other contain the same values. // Note, you must compare the individual elements using .equals(), NOT ==. return false; } return false; } }
Attached to this assignment on blackboard you will find two Java files: LinkedListStack.java and LinkedListStackTests.java. The former file contains a rough outline of all of the methods of a generic, linked-list backed stack. The latter file is a set of test cases. Your assignment is complete the implementation of the linked list in LinkedListStack.java by filling out all of the sections marked TODO. If your implementation passes all of the tests in LinkedListStackTests (except testEquals), you will get full credit for the assignment. The equals method and the testEquals cases are extra credit. The implementation is non-trivial and depends on details of Java we haven't covered (and probably won't). Note, testPopEmptyStack tests that the pop method throws a NoSuchElementException if the stack is empty. It must throw exactly that exception, not a NullPointerException (which is what will likely happen otherwise if you don't add an explicit check). It is fine to use NoSuchElementException's 0- argument constructor Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
