-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLink.java
More file actions
107 lines (77 loc) · 2.08 KB
/
Link.java
File metadata and controls
107 lines (77 loc) · 2.08 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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
import java.util.LinkedList;
import java.util.Scanner;
public class Link {
public static void main(String[] args) {
// TODO Auto-generated method stub
LinkedList<String> ll = new LinkedList<String>();
Scanner console = new Scanner(System.in);
int counter = 0;
int get = 0;
String country = "";
do {
try {
System.out.println("[1] Add Country, [2]Get Country,[3] Set Country, [4] Remove Country, [5]Display Country,[6] Exit");
System.out.print("Enter choice: ");
int choice = console.nextInt();
switch(choice) {
case 1 :
System.out.print("Enter a Country: ");
ll.offer(console.next());
choice =0;
break;
case 2 :
System.out.print("Enter an Index: ");
get = console.nextInt();
for(int i = 0; i < ll.size(); i++) {
if(ll.indexOf(get) > ll.size()) {
System.out.println( "No Element");
}
else {
System.out.println(ll.get(get));
break;
}
}
break;
case 3 :
System.out.print("Enter an Index: ");
get = console.nextInt();
for(int i = 0; i < ll.size(); i++) {
if(ll.indexOf(get) < ll.size()) {
System.out.print("Enter the Name of the Country you want to Set: ");
country = console.next();
ll.set(get, country);
break;
}
else {
System.out.println("Error! No Element");
}
}
break;
case 4 :
System.out.print("Enter a Country that you want to remove: ");
country = console.next();
if(ll.contains(country)) {
ll.remove(country);
choice =0;
}
else {
System.out.println("No Element");
}
break;
case 5 :
if(ll.isEmpty())
System.out.println("Display: Empty");
choice =0;
break;
case 6 :
System.out.print("Confirm to Exit [1] for Yes or [0] for No: ");
int veri = console.nextInt();
counter = (int) (veri == 1 ? 1 : 0);
break;
}
}catch(Exception e) {
System.out.println("Error! Please Enter Again ");
}
}while(counter != 1);
}
}