Question: Java Floodit game public class GenericArrayStack implements Stack { private E[] elems; private int top; @SuppressWarnings( unchecked ) public GenericArrayStack( int capacity ) { elems
Java Floodit game
![Java Floodit game public class GenericArrayStack implements Stack { private E[] elems;](https://dsd5zvtm8ll6.cloudfront.net/si.experts.images/questions/2024/09/66f3e7584a2c3_50366f3e757b2cb2.jpg)

public class GenericArrayStack
private E[] elems; private int top; @SuppressWarnings( "unchecked" )
public GenericArrayStack( int capacity ) { elems = (E[]) new Object[ capacity ]; top = 0; }
public boolean isEmpty() { return top == 0; }
public void push( E elem ) { elems[ top ] = elem; top++;
} public E pop() {
E saved;
top--; saved = elems[ top ]; elems[ top ] = null;
return saved; }
public E peek() {
return elems[ top-1 ]; } }
In the previous version of the game, we have been using a stack implementation that was based on an array. That implementation did not include precondition checks and did not throw any exceptions. We will first switch from an array implementation to a linked element implementation, and add the proper checks and exceptions. 1.1 Linked Stack Implementation (5 marks) You must replace the GenericArrayStack class with a GenericLinkedStack class. Follow the steps seen in class for this. 1.2 Defining new exception types and checking preconditions (5 marks) You must create a new unchecked exception type called EmptyStackException
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
