Question: In Listing 19.1, GenericStack is implemented using composition. Define a new stack class that extends ArrayList. Draw the UML diagram for the classes and then
In Listing 19.1, GenericStack is implemented using composition. Define a new stack class that extends ArrayList. Draw the UML diagram for the classes and then implement GenericStack. Write a test program that prompts the user to enter five strings and displays them in reverse order.
Listing

1 public class GenericStack { private java.util.ArrayList list = new java.util.ArrayList (); 3 public int getSize() { return list.size(); 4. 5 6. public E peek() { return list.get (getSize() - 1); 10 11 public void push(E o) { list.add(o); 12 13 14 15 16 17 18 19 20 public E pop() { E o = list.get(getSize() - 1); list.remove(getSize() - 1); return o; 21 22 public boolean isEmpty() { return list.isEmpty(); 23 24 25 @0verride public String toString() { return "stack: 26 27 + list.toString(); 28 29 30 }
Step by Step Solution
3.50 Rating (160 Votes )
There are 3 Steps involved in it
Program Plan Create a class called Stack The class Stack that extends the Class ArrayLis... View full answer
Get step-by-step solutions from verified subject matter experts
