Shopping List

  1. import java.io.*;
  2. import java.util.*;
  3. class shop
  4. {
  5. DataInputStream ds = new DataInputStream(System.in);
  6.  
  7. void append(Vector v1) throws IOException
  8. {
  9. System.out.println("Enter the element to be Appended");
  10. System.out.println("Current capacity :"+ v1.capacity());
  11. v1.insertElementAt(ds.readLine(),v1.capacity());
  12. System.out.println("Append Successfully");
  13.  
  14. }
  15. void insert(Vector v1) throws IOException
  16. {
  17. System.out.println("Enter the position to be inserted");
  18. Integer x2 = new Integer(ds.readLine());
  19. Integer pos = x2.intValue();
  20. System.out.println("Enter the element");
  21. v1.insertElementAt(ds.readLine(), pos);
  22. System.out.println("Inserted Successfully");
  23. }
  24. void delete(Vector v1) throws IOException
  25. {
  26. System.out.println("Enter the position to be deleted");
  27. Integer x1 = new Integer(ds.readLine());
  28. Integer pos = x1.intValue();
  29. v1.removeElementAt(pos);
  30. System.out.println("Deleted Successfully");
  31.  
  32. }
  33. void display(Vector v1) throws IOException
  34. {
  35. int i=0;
  36. Enumeration vEnum = v1.elements();
  37. System.out.println("\t\t\t Shopping List");
  38. System.out.println("-----------------------");
  39. System.out.println("Items in Vector");
  40. System.out.println("Position Item");
  41. while(vEnum.hasMoreElements())
  42. {
  43. System.out.println(i+"\t\t" +vEnum.nextElement());
  44. i++;
  45.  
  46. }
  47.  
  48.  
  49.  
  50. }
  51.  
  52.  
  53. }
  54. class shoppinglist {
  55. public static void main(String arg[]) throws IOException
  56. {
  57. Vector v = new Vector(5,10);
  58. shop ob = new shop();
  59. DataInputStream ds = new DataInputStream(System.in);
  60. for (int i=0; i<arg.length; i++)
  61. {
  62. v.addElement(arg[i]);
  63. }
  64. ob.display(v);
  65. while(true)
  66. {
  67. System.out.println("\t\t\t Shopping List");
  68. System.out.println("\t\t\t ----------------");
  69. System.out.println("1. Append");
  70. System.out.println("2. Delete");
  71. System.out.println("3. Insert");
  72. System.out.println("4. Display");
  73. System.out.println("5. Exit';");
  74. System.out.println("Enter ur choice");
  75. int ch = Integer.parseInt(ds.readLine());
  76. switch(ch)
  77. {
  78. case 1: ob.append(v);
  79. break;
  80. case 2: ob.delete(v);
  81. break;
  82. case 3: ob.insert(v);
  83. break;
  84. case 4: ob.display(v);
  85. break;
  86. case 5: System.exit(0);
  87. break;
  88. default: System.out.println("Enter correct choice");
  89. break;
  90. }
  91. }
  92.  
  93. }
  94.  
  95. }