Submitted by Karthik on 25 November, 2011 - 21:31
import java.io.*; import java.util.*; class shop { DataInputStream ds = new DataInputStream(System.in); void append(Vector v1) throws IOException { System.out.println("Enter the element to be Appended"); System.out.println("Current capacity :"+ v1.capacity()); v1.insertElementAt(ds.readLine(),v1.capacity()); System.out.println("Append Successfully"); } void insert(Vector v1) throws IOException { System.out.println("Enter the position to be inserted"); Integer x2 = new Integer(ds.readLine()); Integer pos = x2.intValue(); System.out.println("Enter the element"); v1.insertElementAt(ds.readLine(), pos); System.out.println("Inserted Successfully"); } void delete(Vector v1) throws IOException { System.out.println("Enter the position to be deleted"); Integer x1 = new Integer(ds.readLine()); Integer pos = x1.intValue(); v1.removeElementAt(pos); System.out.println("Deleted Successfully"); } void display(Vector v1) throws IOException { int i=0; Enumeration vEnum = v1.elements(); System.out.println("\t\t\t Shopping List"); System.out.println("-----------------------"); System.out.println("Items in Vector"); System.out.println("Position Item"); while(vEnum.hasMoreElements()) { System.out.println(i+"\t\t" +vEnum.nextElement()); i++; } } } class shoppinglist { public static void main(String arg[]) throws IOException { Vector v = new Vector(5,10); shop ob = new shop(); DataInputStream ds = new DataInputStream(System.in); for (int i=0; i<arg.length; i++) { v.addElement(arg[i]); } ob.display(v); while(true) { System.out.println("\t\t\t Shopping List"); System.out.println("\t\t\t ----------------"); System.out.println("1. Append"); System.out.println("2. Delete"); System.out.println("3. Insert"); System.out.println("4. Display"); System.out.println("5. Exit';"); System.out.println("Enter ur choice"); int ch = Integer.parseInt(ds.readLine()); switch(ch) { case 1: ob.append(v); break; case 2: ob.delete(v); break; case 3: ob.insert(v); break; case 4: ob.display(v); break; case 5: System.exit(0); break; default: System.out.println("Enter correct choice"); break; } } } }