package test_01;
import java.util.*;
import java.io.*;
class testver
{
public static void main(String[] args)
{
Vector<String> ver=new Vector<String>(5,1);
ver.add(0," lwj");
ver.add(1, "lwk");
ver.add(2, "lwl");
ver.add(3, "lwh");
ver.add(4, "lwu");
int count=ver.size();
System.out.println("This is a vector!\nThere are "+count+"members:");
System.out.println("NO. Element");
for(int i=0;i<count;i++)
{
System.out.println(" "+i+" "+ver.get(i));
}
System.out.println("You can input <1> or <2> to choose:");
System.out.println("<1>:Add a new element!");
System.out.println("<2>:Delet a element!\n<3>:To viewer all of them!");
System.out.println("<4>:To exit!");
System.out.println("Please choose:");
int j=0;
try {j=System.in.read()-'0';}catch(IOException e){e.getStackTrace();}
while(j==1||j==2||j==3)
{
switch(j)
{
case 1:add(ver);break;
case 2:delet(ver);break;
case 3:vew(ver);break;
}
System.out.println("Please choose again!");
try {j=System.in.read()-'0';}catch(IOException e){e.getStackTrace();}
}
}
public static void add(Vector<String> ver)
{
DataInputStream din=new DataInputStream(System.in);
BufferedInputStream buf=new BufferedInputStream(din);
System.out.println("Please input what you want to add:");
String str;
byte[] in=new byte[100];
try{
buf.read(in);
}catch(IOException e){e.getStackTrace();}
str=in.toString();
ver.addElement(str);
System.out.println("Successed!");
try{
din.close();
buf.close();
}catch(IOException e){e.getStackTrace();}
}
public static void delet(Vector<String> ver)
{
System.out.println("Please input the index of the element you want to delet!");
int index=0;
try{
index=System.in.read();
ver.remove(index);
}catch(IOException e){e.getStackTrace();}
System.out.println("Successed!!");
}
public static void vew(Vector<String> ver)
{
System.out.println("The all elements are:");
System.out.println("NO. Element");
for(int i=0;i<ver.size();i++)
{
System.out.println(" "+ i+" "+ver.get(i));
}
}
}