Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static void main(String[] args) {
- Stack st=new Stack();
- String [] menu={"Set Capacity", "Push", "Pop", "Search", "Clear", "Exit"};
- String message="Capacity: "+st.getCapacity()+"nElements: "+st.display()+
- "nEmpty: "+st.isEmpty()+"nFull: "+st.isFull()+
- "n# of Elements: "+st.count()+"nFirst: "+st.first()+"nLast: "+st.last()+"n";
- String choice="";
- int data=0;
- do{
- choice=(String)JOptionPane.showInputDialog(null, message+"Input Choice:", "Menu", 1, null, menu, menu[0]);
- switch(choice){
- case "Set Capacity":
- st.setCapacity();
- st.getCapacity();
- break;
- case "Push":
- data=Integer.parseInt(JOptionPane.showInputDialog("Enter data: "));
- st.push(data);
- break;
- case "Pop":
- st.pop();
- JOptionPane.showMessageDialog(null, "Popped!");
- break;
- case "Search":
- data=Integer.parseInt(JOptionPane.showInputDialog("Enter data to search: "));
- JOptionPane.showMessageDialog(null, st.search(data));
- break;
- case "Clear":
- st.clear();
- JOptionPane.showMessageDialog(null, "Stack cleared");
- break;
- }
- }while(!choice.equals("Exit"));
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement