Shopping List

Submitted by Karthik on

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("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;="" 2:="" ob.delete(v);="" 3:="" ob.insert(v);="" 4:="" 5:="" system.exit(0);="" default:="" correct=""