Question: Modify and enhance the GenericStack implementation from Chapter 3 so that it conforms to the diagram shown below. Download the Java source code for Chapter
Modify and enhance the GenericStack implementation from Chapter 3 so that it conforms to the diagram shown below.

Download the Java source code for Chapter 3 from the Chapter 3 folder on our Blackboard site, so that you can use the GenericStack class to begin. The default constructor should be modified so that it initializes the array size to 3. The reset method should reinitialize the stack to empty. The peek method should return the object at the top of the stack without removing it. The isEmpty method should test if the stack is empty (underflow condition) and return a boolean (true or false) value. The isFull method should test if the stack is full (overflow condition) and return a boolean value. The expand method is private to this class and you will modifiy the code so that it will only be called when needed. It should expand the stack every time a push operation is performed that would cause an overflow condition.
Write another class named Test that contains a main method. Use this as a driver program to test the methods of the GenericStack class. You need to use a class of objects to put in your stack structure for your tests. This may be the Listing from the text or your Student class for testing but you would have to make sure they implement the GenericNode interface from the text or you will get error messages. Paste your test runs into a Word document to include with your assignment submission.
Include your Java source code files (.java) and your Word document with your program test runs within a Zip file archive (.zip). Name the Zip file according to the convention in the syllabus. This one should be called Assign3B_FirstnameLastname. Upload that in Blackboard to submit your assignment.
// GenericStack.java public class GenericStack
------------------------------------------------------------------------------------------------------------
// GenericNode.java
public interface GenericNode { public abstract GenericNode deepCopy(); // clones the invoking object public abstract String toString(); // added to prevent Objects toString method from // executing. Technically not syntactically necessary. }
------------------------------------------------------------------------------------------------------------
//Listing.java
public class Listing { private String name; private String address; private String number; public Listing() { name = ""; address = ""; number = ""; } public Listing(String n, String a, String num ) { name = n; address = a; number = num; } public String toString( ) { return ("Name is " + name + ' ' + "Address is " + address + ' ' + "Number is " + number + ' '); } public Listing deepCopy( ) { Listing clone = new Listing(name, address, number); return clone; } }
------------------------------------------------------------------------------------------------------------
//MainGenericStack.java
public class MainGenericStack { public static void main(String[] args) { GenericStack
// perform three pushes to fill the stack and then output the stack System.out.println(s.push(l1)); System.out.println(s.push(l2)); System.out.println(s.push(l3)); s.showAll();
// perform three pop operations to empty the stack l = s.pop(); System.out.println(l); l = s.pop(); System.out.println(l); l = s.pop(); System.out.println(l);
// an attempt to perform a pop on an empty stack will return null l = s.pop(); System.out.println(l); System.exit(0); } }
------------------------------------------------------------------------------------------------------------
//ListingGS.java
public class ListingGS implements GenericNode { private String name; private String address; private String number; public ListingGS(String n, String a, String num ) { name = n; address = a; number = num; } public String getKey( ) { return name; } public ListingGS deepCopy() { ListingGS clone = new ListingGS(name, address, number); return clone; } public String toString() { return("Name is " + name + ' ' + "Address is " + address + ' ' + "Number is " + number + ' '); }
public String getNumber() { return number; } public void setNumber(String n) { number = n; } }
------------------------------------------------------------------------------------------------------------
If you need more Java Classes please let me know there is more in the Chapter 3 text but I don't believe that they are needed. Thank you, I will upvote!
GenericStack
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
