- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsample8.java
More file actions
Latest commit
50 lines (43 loc) · 1.46 KB
/
Copy pathsample8.java
File metadata and controls
50 lines (43 loc) · 1.46 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
importjava.util.ArrayList;
importjava.util.LinkedHashSet;
importjava.util.Scanner;
publicclasssample8 {
publicstaticvoidgetData(LinkedHashSet<Bank> bankHashSet) {
Scannersc = newScanner(System.in);
Stringstr = "";
do {
System.out.println("enter data");
Bankb = newBank();
b.setAccid(sc.nextInt());
sc.nextLine();
b.setAccName(sc.nextLine());
b.setAccBal(sc.nextInt());
booleanexist = alreadyExist(bankHashSet, b);
if (!exist)
bankHashSet.add(b);
sc.nextLine();
System.out.println("Do you want to continue?");
str = sc.nextLine();
} while (str.equals("y"));
sc.close();
}
publicstaticbooleanalreadyExist(LinkedHashSet<Bank> bankHashSet, Bankb) {
for (Bankbank : bankHashSet) {
if (bank.getAccid() == b.getAccid()) {
System.out.println("Acc Id already exists");
returntrue;
}
}
returnfalse;
}
publicstaticvoiddisplay(LinkedHashSet<Bank> bankHashSet) {
for (Bankb : bankHashSet) {
System.out.println(b.getAccid() + " --- " + b.getAccName() + " - " + b.getAccBal());
}
}
publicstaticvoidmain(String[] args) {
LinkedHashSet<Bank> bankHashSet = newLinkedHashSet<>();
getData(bankHashSet);
display(bankHashSet);
}
}