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;

private int top; @SuppressWarnings( "unchecked" ) public GenericArrayStack( int capacity ) {

public class GenericArrayStack implements Stack {

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

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!