-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathCityVector.java
More file actions
58 lines (54 loc) · 2.06 KB
/
CityVector.java
File metadata and controls
58 lines (54 loc) · 2.06 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
import java.util.Iterator;
import java.util.Scanner;
import java.util.Vector;
public class CityVector {
public static void main(String[] args){
Vector<String> v = new Vector<String>();
Scanner input = new Scanner(System.in);
boolean show = true;
while(show){
System.out.println("Menu:");
System.out.println("1. Add City");
System.out.println("2. Remove City");
System.out.println("3. Show All Cities");
System.out.println("4. Exit");
System.out.println("Enter your choice: ");
int choice = input.nextInt();
input.nextLine();
switch(choice){
case 1:
System.out.println("Enter name of the City to add: ");
String name = input.nextLine();
if(v.contains(name)){
System.out.println("City already entered");
}else{
v.add(name);
System.out.println("City added successfully");
}
break;
case 2:
System.out.println("Enter name of the City to remove: ");
String n = input.nextLine();
if(v.contains(n)){
v.remove(n);
System.out.println("City removed successfully");
}else{
System.out.println("City doesn't exist");
}
break;
case 3:
Iterator itr = v.iterator();
while(itr.hasNext()){
System.out.println(itr.next());
}
break;
case 4:
show = false;
System.out.println("Menu exited");
break;
default:
System.out.println("Invalid choice");
}
}
}
}