Description
In chapter 4, we studied the StackX class and learned how to implement a stack using an array. Unfortunately, the stack we created was limited by the length of the underlying array, and it can store only one data type. In the subsequent chapters, we learned how to make a dynamic data structure and create generic classes to overcome the mentioned issues. In this assignment, you will create a _generic_ class for a dynamic stack that can store data of any type, both primitive and non-primitive type.
## Specifically, your class should contain
1. No-arg constructor // Initialize an empty stack.
2. Push(E item) method // Push a new item onto the stack.
3. Pop() method // Get the top item, removing it from the stack.
4. Peek() method // Get the top item of the stack without removing the item.
5. IsEmpty() method // determine whether the stack is empty. Returns true if this stack is empty; otherwise, false.
6. Size() method // Accessor method to determine the number of items in the stack. Returns the number of items in this stack.
7. Clone() method // Generate a copy of the stack. The return value is a copy of the stack. Subsequent changes to the copy will not affect the original, nor vice versa.
8. Display() method // Print the contents of the stack.
To earn full credit, you must demonstrate the class with a driver program. The driver should test the following cases:
1. Create (declare) an integer stack:
a- Print the stack (the stack is empty).
b- Pushing items onto the stack.
c- Print the stack (You need to use the size() to iterate over the stack).
d- Generate a copy of this stack.
e- Remove several items from the original stack (using pop() method).
f- Print the original stack and its clone.
2. Create (declare) a string stack:
a- Print the stack (the stack is empty).
b- Pushing items onto the stack.
c- Print the stack (You need to use the size() to iterate over the stack).
d- Generate a copy of this stack.
e- Remove several items from the original stack (using pop() method).
f- Print the original stack and its clone.
Notes:
1. The program must compile without syntax errors; 50% of the assignment points will be deducted if your program does not compile, even if your program is “essentially” correct.
2. To get full credit for an assignment, your program must solve the assignment problem completely.
3. Please add comments to the source code. Your program should have a reasonable amount of comments.
4. At the very beginning of each file, there should be a block comment containing the student name, course number, and assignment number.
5. Follow the programming styles and guidelines discussed in class, such as using meaningful names for variables and camel case conventions for variables, classes, etc.
6. Using ChatGPT or any LLM is not allowed. Your code will be examined if written using an AI tool.
7. You are not allowed to use the ArrayList class or any method from the Array APIs (except System.arraycopy()) to implement this assignment – you will lose 60% of the points if your code is implemented using the mentioned APIs.
8. To submit your Java files on Moodle:
a. Create a folder with your last name.
b. Place your Java files inside the folder.
c. Zip the folder.
d. Upload it to Moodle.