-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathBankingOperation.java
More file actions
279 lines (277 loc) · 10.1 KB
/
BankingOperation.java
File metadata and controls
279 lines (277 loc) · 10.1 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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
/*
@Banking application - With the help of this application we can create new bank
account and other banking operation's.
@Author - Nitheesh G.
@Created at - 02-11-2021
@Updated at - 02-16-2021
@Reviewed by - Anto
*/
package bankapplication;
import static java.lang.System.exit;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Scanner;
import java.util.regex.Pattern;
class BankingOperation implements Transaction
{
boolean flag;
Scanner input=new Scanner(System.in);
static HashSet<UserDetails>UserDetailSet=new HashSet<>();
void CreateNewBankAccount() // To creating new user bank account
{
UserDetails userdetails=new UserDetails();
System.out.println("---------------Enter Your Detail's------------------");
flag=true; // Validating First Name
while(flag)
{
try
{
System.out.println("Enter your first Name :");
String firstname=input.next();
if(Pattern.matches("[A-Za-z]*",firstname))
{
userdetails.setFirstname(firstname);
flag=false;
}
else
{
flag=true;
throw new InvalidFirstNameException("Please provide the correct First Name.\n");
}
}
catch(InvalidFirstNameException e)
{
System.out.println("You're Entering the Invaild First Name.\n"+e);
}
}
flag=true; // Validating Last Name
while(flag)
{
try
{
System.out.println("Enter your Last Name :");
String lastname=input.next();
if(Pattern.matches("[A-Za-z]*",lastname))
{
userdetails.setLastname(lastname);
flag=false;
}
else
{
flag=true;
throw new InvalidLastNameException("Please provide the correct Last Name.\n");
}
}
catch(InvalidLastNameException e)
{
System.out.println("You're Entering the Invaild Last Name.\n"+e);
}
}
flag=true; // Validating Aadhar Number
while(flag)
{
try
{
String AadharRegex = "^[2-9]{1}[0-9]{3}[0-9]{4}[0-9]{4}$";
System.out.println("Enter your Aadhar Number :");
String Aadharnumber=input.next();
if(Aadharnumber.matches(AadharRegex))
{
userdetails.setAadharnumber(Aadharnumber);
flag=false;
}
else
{
flag=true;
throw new InvalidAadharException("Please provide the correct Aadhar Number.\n");
}
}
catch(InvalidAadharException e)
{
System.out.println("You're Entering the Invaild Aadhar Number.\n"+e);
}
}
flag=true; // Validating Age
while(flag)
{
System.out.println("Enter your Age :");
int age=input.nextInt();
try
{
if(age>=18)
{
userdetails.setAge(age);
flag=false;
}
else if((age>=1) && (age<=17))
{
System.out.println("You're in under 18, so not eligible to create Bank Account. please Contact You're nearest branch.\n************ Thank you for using our service! Have a GREAT DAY **************");
exit(0);
}
else
{
flag=true;
throw new InvalidAgeException("Please provide the correct age.\n");
}
}
catch(InvalidAgeException e)
{
System.out.println("You're Entering the Invaild age.\n"+e);
}
}
flag=true; // Validating Mobile Number
while(flag)
{
try
{
String MobileNumberregex = "[6-9]{1}[0-9]{9}"; //(0/91)?
System.out.println("Enter your Mobile Number :");
String mobilenumber=input.next();
if(mobilenumber.length()==10 && mobilenumber.matches(MobileNumberregex))
{
userdetails.setMobilenumber(mobilenumber);
flag=false;
}
else
{
flag=true;
throw new InvalidMobileNumberException("Please provide the correct Mobile Number.\n");
}
}
catch(InvalidMobileNumberException e)
{
System.out.println("You're Entering the Invaild MoblieNumber.\n"+e);
}
}
//System.out.println("For new account opening, Please deposite the Minimum Balance Amount 1000 in your account:");
userdetails.setBalanceamount(0);
userdetails.setAccountnumber();
UserDetailSet.add(userdetails);
System.out.println(".....................Your's New Bank account was successfully created......................");
System.out.println("Your Account Number is : "+userdetails.getAccountnumber());
System.out.println("Your Account Balance is : "+userdetails.getBalanceamount());
System.out.println("Your Account Balance is very low, So please depoite money for further transaction's.\n");
}
@Override
public void DepositeUserMoney() //To deposite money
{
int Depositeflag = 0;
//Pattern pattern=Pattern.compile("[a-zA-Z]*");
System.out.println("Enter Account number: ");
long accountNumber = input.nextLong();
String ConvertAccountNumber=String.valueOf(accountNumber);
if(!(Pattern.matches("[a-zA-Z]",ConvertAccountNumber)))
{
Iterator<UserDetails> iterator = UserDetailSet.iterator();
UserDetails userdetails;
while(iterator.hasNext())
{
userdetails = (UserDetails) iterator.next();
if(userdetails.getAccountnumber()== accountNumber)
{
Depositeflag = 1;
System.out.println("Enter Deposit amount: ");
int depositAmount = input.nextInt();
userdetails.setBalanceamount(userdetails.getBalanceamount()+depositAmount);
System.out.println("Successfully money deposited to your account number "+userdetails.getAccountnumber()+".\n");
History history = new History();
history.CreditAmount = depositAmount;
history.TotalAmount = userdetails.getBalanceamount();
if(userdetails.TransactionHistory.size()>=5)
{
userdetails.TransactionHistory.remove();
userdetails.TransactionHistory.add(history);
}
else
{
userdetails.TransactionHistory.add(history);
}
break;
}
}
if(Depositeflag == 0)
{
System.out.println("Account Number Not Created.\n");
}
}
else
{
System.out.println("You're enter the invalid Account Number.\n");
}
}
@Override
public void WithdrawUserMoney() //To withdraw money
{
int Withdrawflag = 0;
System.out.println("Enter Account number: ");
int accountNumber = input.nextInt();
Iterator<UserDetails> iterator = UserDetailSet.iterator();
UserDetails userdetails;
while(iterator.hasNext())
{
userdetails = (UserDetails) iterator.next();
if(userdetails.getAccountnumber()== accountNumber)
{
Withdrawflag = 1;
System.out.println("Enter withdraw amount: ");
int withdrawAmount = input.nextInt();
if(userdetails.getBalanceamount()-withdrawAmount >= 600)
{
userdetails.setBalanceamount(userdetails.getBalanceamount()-withdrawAmount);
System.out.println("----------------Successfully withdrawn, Please collect your Cash----------------\n");
History History = new History();
History.DebitAmount = withdrawAmount;
History.TotalAmount = userdetails.getBalanceamount();
if(userdetails.TransactionHistory.size()>=5)
{
userdetails.TransactionHistory.remove();
userdetails.TransactionHistory.add(History);
}
else
{
userdetails.TransactionHistory.add(History);
}
}
else
{
System.out.println("Insufficient Balance\n");
}
break;
}
}
if(Withdrawflag == 0)
{
System.out.println("Invalid Account Number\n");
}
}
@Override
public void DisplayUserAccountDetails() //To display the userdetails
{
int Displayflag=0;
System.out.println("Enter your Account number to display your bank details :");
long AccountNumber=input.nextLong();
Iterator<UserDetails> iterator=UserDetailSet.iterator();
UserDetails userdetails;
while(iterator.hasNext())
{
userdetails=(UserDetails)iterator.next();
if(userdetails.getAccountnumber()==AccountNumber)
{
Displayflag=1;
System.out.println("----------------Account Details-----------------");
System.out.println("Account Number : "+userdetails.getAccountnumber());
System.out.println("First Name : "+userdetails.getFirstname());
System.out.println("Last Name : "+userdetails.getLastname());
System.out.println("Age : "+userdetails.getAge());
System.out.println("Phone Number: "+userdetails.getMobilenumber());
//System.out.println("Aadhar Number: "+userdetails.getAadhar_number());
System.out.println("Account Balance :"+userdetails.getBalanceamount()+"\n");
break;
}
}
if(Displayflag==0)
{
System.out.println("Invalid Account Number\n");
}
}
}