Question: Exercise 2: You would recall from your first year CS course that a stack is a last in, first out data structure that has push,

 Exercise 2: You would recall from your first year CS coursethat a stack is a last in, first out data structure that Exercise 2: You would recall from your first year CS course that a stack is a last in, first out data structure that has push, pop and peek as its basic operations. In this exercise, you will create a simple generic stack class that is implemented with an ArrayList to store the stack elements. The UML diagram is given below. The initial part of the code is given below: GenericStack - stack: ArrayList + GenericStack() + getSize(): int + peek(): T + pop(): T + push(T element): void +isEmpty(): boolean 3 import java.util.ArrayList; public class GenericStack { private ArrayList stack; //continue } As an example of its use, write a small test (demo or client program) to create two stacks, one to hold strings and another to hold integer objects, and test the methods: import java.util.Scanner; import java.util.ArrayList; public class GenericStackDemo{ public static void main(){ GenericStack stack1 = new GenericStack(); GenericStack stack2 = new GenericStack(); //continue } Your program should accept input from the user, push each item into the stack and display the stack contents. A sample screen dialog is given below. Try it for three different input sets and include the screen dialogs in your output text file. String Stack: Enter a word (quit to end): London Enter a word (quit to end): Paris Enter a word (quit to end): Halifax Enter a word (quit to end): quit Integer Stack: Enter a positive integer (-1 to end): 100 Enter a positive integer (-1 to end): 200 Enter a positive integer (-1 to end): 300 Enter a positive integer (-1 to end): 400 Enter a positive integer (-1 to end): -1 String Stack Contents: Halifax Paris London Integer Stack Contents: 400 300 200 100

Exercise 2: You would recall from your first year CS course that a stack is a last in, first out data structure that has push, pop and peek as its basic operations. In this exercise, you will create a simple generic stack class that is implemented with an ArrayList to store the stack elements. The UML diagram is given below GenericStack - stack: ArrayList i private ArrayList stack; //continue

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!