Question: Using GenericStack.java Write a program to create two stacks, stack1 for String and stack2 for Integers. Use the push method to push three Strings, London,

Using GenericStack.java

Write a program to create two stacks, stack1 for String and stack2 for Integers.

Use the push method to push three Strings, London, Paris and Berlin, onto stack1.

Use the push method to push three Integers, 1, 2 and 3, onto stack2.

Use the peek method to display to top value on stack1

Write code to pop and display all stack1 values. Verify that stack1 is empty at the end of step c.

Do steps c and d using stack2

ps: This is what we have in GenericStack.java

import java.util.*; public class GenericStack { private ArrayList list = new ArrayList(); public int getSize() { return list.size(); } public E peek() { return list.get(getSize() - 1); } public void push(E o) { list.add(o); } public E pop() { E o = list.get(getSize() - 1); list.remove(getSize() - 1); return o; } public boolean isEmpty() { return list.isEmpty(); } } 

Thank you

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!