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();

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

1 Expert Approved Answer
Step: 1 Unlock

Program that prompts the user to enter five strings and display them in reverse order UML diagram ... View full answer

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 Java Programming Questions!