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


1 import java.util.ArrayList; 2 3 public class MyStack { 4 private ArrayList list = new ArrayList (); 5 public boolean isEmpty() { return list.isEmpty(); 6 public int getSize() { return list.size(); 10 11 12 13 14 public Object peek() { return list.get(getSize() - 1); 15 16 17 18 public Object pop() { Object o = list.get(getSize() - 1); list.remove (getSize() - 1); 19 20 21 22 23 24 25 26 27 28 return o; public void push(0bject o) { list.add(o); @Override public String toString() { return "stack: " + list.toString(); 29 30 31 32 }
Step by Step Solution
3.38 Rating (173 Votes )
There are 3 Steps involved in it
Program that prompts the user to enter five strings and display them in reverse order UML diagram ... View full answer
Get step-by-step solutions from verified subject matter experts
