Advertisement
Guest User

Untitled

a guest
Jul 31st, 2016
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.29 KB | None | 0 0
  1. public static void main(String[] args) {
  2. Stack st=new Stack();
  3.  
  4. String [] menu={"Set Capacity", "Push", "Pop", "Search", "Clear", "Exit"};
  5. String message="Capacity: "+st.getCapacity()+"nElements: "+st.display()+
  6. "nEmpty: "+st.isEmpty()+"nFull: "+st.isFull()+
  7. "n# of Elements: "+st.count()+"nFirst: "+st.first()+"nLast: "+st.last()+"n";
  8.  
  9.  
  10. String choice="";
  11. int data=0;
  12.  
  13. do{
  14. choice=(String)JOptionPane.showInputDialog(null, message+"Input Choice:", "Menu", 1, null, menu, menu[0]);
  15.  
  16. switch(choice){
  17. case "Set Capacity":
  18. st.setCapacity();
  19. st.getCapacity();
  20. break;
  21. case "Push":
  22. data=Integer.parseInt(JOptionPane.showInputDialog("Enter data: "));
  23. st.push(data);
  24. break;
  25. case "Pop":
  26. st.pop();
  27. JOptionPane.showMessageDialog(null, "Popped!");
  28. break;
  29. case "Search":
  30. data=Integer.parseInt(JOptionPane.showInputDialog("Enter data to search: "));
  31. JOptionPane.showMessageDialog(null, st.search(data));
  32. break;
  33. case "Clear":
  34. st.clear();
  35. JOptionPane.showMessageDialog(null, "Stack cleared");
  36. break;
  37. }
  38. }while(!choice.equals("Exit"));
  39.  
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement