-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBankingApplication_CustomerFileHandler
More file actions
85 lines (77 loc) · 2.58 KB
/
BankingApplication_CustomerFileHandler
File metadata and controls
85 lines (77 loc) · 2.58 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
import java.io.*;
import java.util.Arrays;
import java.lang.*;
public class CustomerFileHandler {
Customer []customer;
private static String filename = "Bankfile.txt";
public void intialize() {
customer=new Customer[20];
File file = new File("G:\\My Drive\\notpad\\waste.txt");
FileReader fileReader= null;
try {
fileReader = new FileReader(file);
} catch (FileNotFoundException e) {
throw new RuntimeException(e);
}
BufferedReader reader = new BufferedReader(fileReader);
String coustomerinfo = null;
try {
coustomerinfo = reader.readLine();
} catch (IOException e) {
throw new RuntimeException(e);
}
int count=0;
do{
customer[count++]=costomerdiv(coustomerinfo);
try {
coustomerinfo= reader.readLine();
} catch (IOException e) {
throw new RuntimeException(e);
}
}while(coustomerinfo!=null);
Bank.customer=customer;
Bank.count=count-1;
Bank.accountnumber=customer[count-1].accountId;
Bank.custid=customer[count-1].CustomerId;
// fileReader.close();
}
private static Customer costomerdiv(String coustomerinfo) {
String[] cu=coustomerinfo.split(" ");
Customer cust=new Customer(
Integer.parseInt(cu[0]),
cu[2],
Double.parseDouble(cu[3].toString()),
cu[4],
Integer.parseInt(cu[1].toString())
);
return cust;
}
public void addCustomer(String name, String password, String repassword) throws IOException {
if(!password.equals(repassword)) {
System.out.println("mismatch password");
}else{
Bank.count++;
Bank.custid++;
Bank.accountnumber++;
Customer cust=new Customer(Bank.custid,name,Bank.BALENCE,password,Bank.accountnumber);
customer[Bank.count]=cust;
writeFile(customer[Bank.count]);
}
}
private void writeFile(Customer customer) {
File file = new File("G:\\My Drive\\notpad\\waste.txt");
FileWriter write= null;
try {
write = new FileWriter(file,true);
write.write("\n"+customer.toString());
} catch (IOException e) {
throw new RuntimeException(e);
}finally {
try {
write.close();
} catch (IOException e) {
throw new RuntimeException(e);
}
}
}
}