-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMenuDriven_Shoppinglist.java
More file actions
70 lines (65 loc) · 1.95 KB
/
Copy pathMenuDriven_Shoppinglist.java
File metadata and controls
70 lines (65 loc) · 1.95 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
package Examples;
import java.util.*;
import java.io.*;
public class MenuDriven_Shoppinglist {
public static void main(String args[])
{
int choice=0, index, len;
String item, str;
Vector v = new Vector();
Scanner sc = new Scanner(System.in);
len = args.length;
for(int i=0;i<len;i++)
v.addElement(args[i]);
System.out.println("***MENU***");
System.out.println("1. Add item at specified location");
System.out.println("2. Add item at the END");
System.out.println("3. Delete an item");
System.out.println("4. Show all the items");
System.out.println("5. Exit");
do
{
try
{
System.out.flush();
BufferedReader obj = new BufferedReader(new InputStreamReader(System.in));
System.out.print("Select your Operation: ");
str=sc.nextLine();
choice=Integer.parseInt(str);
switch(choice)
{
case 1:
System.out.flush();
System.out.print("Enter Item to be Insert: ");
item=obj.readLine();
System.out.print("Enter Position to insert item: ");
str=obj.readLine();
index=Integer.parseInt(str);
v.insertElementAt(item,index-1);
break;
case 2:
System.out.flush();
System.out.print("Enter Item name: ");
item=sc.nextLine();
v.add(item);
break;
case 3:
System.out.print("Enter the Item: ");
str=sc.nextLine();
v.removeElement(str);
break;
case 4:
System.out.println("Items in the list are: ");
for(int i=0; i<v.size();i++)
System.out.println((i+1)+": "+v.elementAt(i));
break;
case 5:
System.out.println(" Thank You!!");
System.exit(0);
default:
System.out.println("Oppss.. Invalid Choice");
}
}catch(Exception e) {}
}while(choice!=5);
}
}