-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSet5_CustomerDetails.java
More file actions
58 lines (39 loc) · 1.49 KB
/
Copy pathSet5_CustomerDetails.java
File metadata and controls
58 lines (39 loc) · 1.49 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.io.*;
import java.util.*;
public class Set5_CustomerDetails {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("Enter Name");
String name = sc.nextLine();
StringBuilder read_data = readCustomerDetails();
searchCustomer(read_data, name);
sc.close();
}
public static void searchCustomer(StringBuilder read_data, String name) {
String[] lines = read_data.toString().split("\n");
for (int i = 0; i < lines.length; i++) {
lines[i] = lines[i].replaceAll("\n", ",");
}
String result = String.join(",", lines);
String[] fields = result.toString().split(",");
for (int i = 0; i < fields.length; i++) {
if (name.equals(fields[i])) {
System.out.println(fields[i + 1]);
System.out.println(fields[i + 2]);
}
}
}
public static StringBuilder readCustomerDetails() {
String line_of_file;
StringBuilder read_data = new StringBuilder();
try {
BufferedReader bf = new BufferedReader(new FileReader(new File("CustomerDetails.txt")));
while ((line_of_file = bf.readLine()) != null) {
read_data.append(line_of_file).append("\n");
}
} catch (IOException e) {
System.out.println(e);
}
return read_data;
}
}