-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsample8.java
More file actions
50 lines (43 loc) · 1.46 KB
/
sample8.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
import java.util.ArrayList;
import java.util.LinkedHashSet;
import java.util.Scanner;
public class sample8 {
public static void getData(LinkedHashSet<Bank> bankHashSet) {
Scanner sc = new Scanner(System.in);
String str = "";
do {
System.out.println("enter data");
Bank b = new Bank();
b.setAccid(sc.nextInt());
sc.nextLine();
b.setAccName(sc.nextLine());
b.setAccBal(sc.nextInt());
boolean exist = 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();
}
public static boolean alreadyExist(LinkedHashSet<Bank> bankHashSet, Bank b) {
for (Bank bank : bankHashSet) {
if (bank.getAccid() == b.getAccid()) {
System.out.println("Acc Id already exists");
return true;
}
}
return false;
}
public static void display(LinkedHashSet<Bank> bankHashSet) {
for (Bank b : bankHashSet) {
System.out.println(b.getAccid() + " --- " + b.getAccName() + " - " + b.getAccBal());
}
}
public static void main(String[] args) {
LinkedHashSet<Bank> bankHashSet = new LinkedHashSet<>();
getData(bankHashSet);
display(bankHashSet);
}
}