Advertisement
Guest User

Untitled

a guest
Feb 21st, 2017
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.97 KB | None | 0 0
  1. My Main:
  2.  
  3. package arraylist;
  4.  
  5. import java.util.Scanner;
  6.  
  7. /**
  8. *
  9. * @author dghelardini
  10. */
  11. public class ArrayList {
  12.  
  13. /**
  14. * @param args the command line arguments
  15. */
  16. public static void main(String[] args)
  17. {
  18.  
  19. Scanner userIn = new Scanner(System.in);
  20. System.out.print("Enter five names: ");
  21.  
  22.  
  23. }
  24.  
  25.  
  26.  
  27. }
  28.  
  29.  
  30. MyStack Class:
  31.  
  32. package arraylist;
  33.  
  34. /**
  35. *
  36. * @author dghelardini
  37. */
  38. public class MyStack extends ArrayList
  39. {
  40. private ArrayList<Object> theList = new ArrayList<>();
  41.  
  42. public boolean isEmpty()
  43. {
  44. return theList.isEmpty();
  45. }
  46.  
  47. public int getSize()
  48. {
  49. return theList.size();
  50. }
  51.  
  52. public Object peek()
  53. {
  54. return theList.get(getSize()-1);
  55. }
  56.  
  57. public Object pop()
  58. {
  59. Object o = theList.get(getSize()-1);
  60. theList.remove(getSize()-1);
  61. return o;
  62. }
  63.  
  64. public void push(Object o)
  65. {
  66. theList.add(o);
  67. }
  68.  
  69. @Override
  70. public String toString()
  71. {
  72.  
  73. return "stack:" + theList.toString();
  74. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement