Account.java
1 package account;
2
3 public class Account
4 {
5 private String accountID;
6 private String accountname;
7 private String accountpassword;
8 private int accountbalance;
9 private int operatetype;
10 private String operatedate;
11 private int amount;
12
13 /**
14 * @param accountID 用户账号
15 * @param accountname 账户的名称
16 * @param accountpassword 用户密码
17 * @param accountbalance 账户余额
18 * @param operatetype 操作账户的类型
19 * @param operatedate 操作的时间
20 * @param amount 流水金额
21 */
22 public Account()
23 {
24 this.setAccountID("");
25 this.setAccountname("");
26 this.setAccountpassword("");
27 this.setAccountbalance(0);
28 }
29 public Account(String accountID, String accountname, String accountpassword, int accountbalance)
30 {
31 this.setAccountID(accountID);
32 this.setAccountname(accountname);
33 this.setAccountpassword(accountpassword);
34 this.setAccountbalance(accountbalance);
35 // Date now = new Date();
36 // SimpleDateFormat ft = new SimpleDateFormat("yyyy-MM-dd");
37 // operatedate = ft.format(now);
38 }
39
40 public String getAccountID()
41 {
42 return accountID;
43 }
44
45 public void setAccountID(String accountID)
46 {
47 this.accountID = accountID;
48 }
49
50 public String getAccountname()
51 {
52 return accountname;
53 }
54
55 public void setAccountname(String accountname)
56 {
57 this.accountname = accountname;
58 }
59
60 public String getAccountpassword()
61 {
62 return accountpassword;
63 }
64
65 public void setAccountpassword(String accountpassword)
66 {
67 this.accountpassword = accountpassword;
68 }
69
70 public int getAccountbalance()
71 {
72 return accountbalance;
73 }
74
75 public void setAccountbalance(int accountbalance)
76 {
77 this.accountbalance = accountbalance;
78 }
79
80 public int getOperatetype()
81 {
82 return operatetype;
83 }
84
85 public void setOperatetype(int operatetype)
86 {
87 this.operatetype = operatetype;
88 }
89
90 public String getOperatedate()
91 {
92 return operatedate;
93 }
94
95 public void setOperatedate(String operatedate)
96 {
97 this.operatedate = operatedate;
98 }
99
100 public int getAmount()
101 {
102 return amount;
103 }
104
105 public void setAmount(int amount)
106 {
107 this.amount = amount;
108 }
109 }
AccountManager.java
1 package account;
2
3 import java.util.*;
4 import java.io.*;
5 import java.nio.file.Paths;
6 import java.text.SimpleDateFormat;
7
8 public class AccountManager
9 {
10 private Account[] AccountList;
11 private Account Account_now;
12
13 public AccountManager()
14 {
15 AccountList = new Account[5];
16 AccountList[0] = new Account("20173475", "韩一祺", "123456", 99999999);
17 AccountList[1] = new Account("20173476", "韩二祺", "123456", 99999998);
18 AccountList[2] = new Account("20173477", "韩三祺", "123456", 99999997);
19 AccountList[3] = new Account("20173478", "韩四祺", "123456", 99999996);
20 AccountList[4] = new Account("20173479", "韩五祺", "123456", 99999995);
21 }
22
23 public void GUI()
24 {
25 filewrite();
26 fileload();
27 int n = 0;
28 Scanner in = new Scanner(System.in);
29 System.out.print("***************************************************************\r\n" + "欢迎使用中国工商银行自动柜员系统\r\n"
30 + "****************************************************************\r\n"
31 + " 请输入您的账号:\r\n"
32 + "****************************************************************\r\n");
33 String accountID = in.nextLine();
34 Account_now = new Account();
35 while (true)
36 {
37 select_account(accountID);
38 if (Account_now.getAccountID().equals(""))
39 {
40 System.out.println("未找到该账户");
41 GUI();
42 } else
43 {
44 GUI3();
45 }
46 String accountpassword = in.nextLine();
47 if (accountpassword.equals(Account_now.getAccountpassword()))
48 {
49 GUI2();
50 } else
51 {
52 n++;
53 if (n < 3)
54 {
55 System.out.println("密码录入错误");
56 } else
57 {
58 System.out.println("该账号三次录入密码错误,该卡已被系统没收,请与工行及时联系处理");
59 GUI();
60 }
61 }
62 }
63 }
64
65 public void GUI2()
66 {
67 System.out.printf(
68 "***************************************************************\r\n" + "欢迎%s使用中国工商银行自助柜员系统\r\n"
69 + "****************************************************************\r\n" + "1、 存款;\r\n"
70 + "2、 取款;\r\n" + "3、 转账汇款;\r\n" + "4、 修改密码;\r\n" + "5、 查询余额;\r\n"
71 + "****************************************************************\r\n",
72 Account_now.getAccountname());
73 Scanner in = new Scanner(System.in);
74 String key = in.nextLine();
75 switch (key)
76 {
77 case "1":
78 deposit();
79 GUI2();
80 break;
81 case "2":
82 withdraw();
83 GUI2();
84 break;
85 case "3":
86 transfer();
87 GUI2();
88 break;
89 case "4":
90 chang_password();
91 GUI2();
92 break;
93 case "5":
94 inquiry_balance();
95 GUI2();
96 break;
97 default:
98 GUI();
99 break;
100 }
101 }
102
103 public void GUI3()
104 {
105 System.out.print("***************************************************************\r\n");
106 System.out.printf("欢迎%s使用中国工商银行自助柜员系统\r\n", Account_now.getAccountname());
107 System.out.print("****************************************************************\r\n");
108 System.out.print(" 请输入您的密码:\r\n");
109 System.out.print("****************************************************************\r\n");
110 }
111
112 private void select_account(String accountID)
113 {
114 for (Account a : AccountList)
115 {
116 if (a.getAccountID().equals(accountID))
117 {
118 Account_now = a;
119 Date now = new Date();
120 SimpleDateFormat ft = new SimpleDateFormat("yyyy-MM-dd");
121 Account_now.setOperatedate(ft.format(now));
122 }
123 }
124 }
125
126 public void fileload()
127 {
128 int i=0;
129 Scanner in=null;
130 try
131 {
132 in=new Scanner(Paths.get("accountinfomation.txt"));
133 } catch (IOException e)
134 {
135 e.printStackTrace();
136 }
137 while(i<5)
138 {
139 AccountList[i].setAccountID(in.nextLine());
140 AccountList[i].setAccountname(in.nextLine());
141 AccountList[i].setAccountpassword(in.nextLine());
142 AccountList[i].setAmount(Integer.valueOf(in.nextLine()));
143 in.nextLine();
144 i++;
145 }
146 }
147
148 public void filewrite()
149 {
150 PrintWriter out=null;
151 try
152 {
153 OutputStream f = new FileOutputStream("accountinfomation.txt",false);
154 out=new PrintWriter(f);
155 } catch (FileNotFoundException e)
156 {
157 e.printStackTrace();
158 }
159 for(Account e:AccountList)
160 {
161 select_account(e.getAccountID());
162 out.println(Account_now.getAccountID());
163 out.println(Account_now.getAccountname());
164 out.println(Account_now.getAccountpassword());
165 out.println(Account_now.getAmount());
166 out.println();
167 }
168 out.close();
169 }
170
171 public void withdraw()
172 {
173 int number = 0;
174 boolean flag = false;
175 System.out.printf(
176 "***************************************************************\r\n" + "欢迎%s使用中国工商银行自助柜员系统\r\n"
177 + "****************************************************************当前账户每日可以支取2万元。\r\n"
178 + "1、100元\r\n" + "2、500元\r\n" + "3、1000元\r\n" + "4、1500元\r\n" + "5、2000元\r\n" + "6、5000元;\r\n"
179 + "7、其他金额\r\n" + "8、退卡\r\n" + "9、返回\r\n"
180 + "****************************************************************\r\n",
181 Account_now.getAccountname());
182 Scanner in = new Scanner(System.in);
183 int key = in.nextInt();
184 switch (key)
185 {
186 case 1:
187 number = 100;
188 if (Account_now.getAccountbalance() < 100)
189 System.out.println("账户余额不足");
190 else
191 {
192 Account_now.setAccountbalance(Account_now.getAccountbalance() - 100);
193 flag = true;
194 }
195 break;
196 case 2:
197 number = 500;
198 if (Account_now.getAccountbalance() < 500)
199 System.out.println("账户余额不足");
200 else
201 {
202 Account_now.setAccountbalance(Account_now.getAccountbalance() - 500);
203 flag = true;
204 }
205 break;
206 case 3:
207 number = 1000;
208 if (Account_now.getAccountbalance() < 1000)
209 System.out.println("账户余额不足");
210 else
211 {
212 Account_now.setAccountbalance(Account_now.getAccountbalance() - 1000);
213 flag = true;
214 }
215 break;
216 case 4:
217 number = 1500;
218 if (Account_now.getAccountbalance() < 1500)
219 System.out.println("账户余额不足");
220 else
221 {
222 Account_now.setAccountbalance(Account_now.getAccountbalance() - 1500);
223 flag = true;
224 }
225 break;
226 case 5:
227 number = 2000;
228 if (Account_now.getAccountbalance() < 2000)
229 System.out.println("账户余额不足");
230 else
231 {
232 Account_now.setAccountbalance(Account_now.getAccountbalance() - 2000);
233 flag = true;
234 }
235 break;
236 case 6:
237 number = 5000;
238 if (Account_now.getAccountbalance() < 5000)
239 System.out.println("账户余额不足");
240 else
241 {
242 Account_now.setAccountbalance(Account_now.getAccountbalance() - 5000);
243 flag = true;
244 }
245 break;
246 case 7:
247 System.out.print("请输入取款金额:");
248 number = in.nextInt();
249 if (Account_now.getAccountbalance() < number)
250 System.out.println("账户余额不足");
251 else
252 {
253 Account_now.setAccountbalance(Account_now.getAccountbalance() - number);
254 flag = true;
255 }
256 break;
257 case 8:
258 GUI();
259 number = 0;
260 break;
261 case 9:
262 GUI2();
263 number = 0;
264 break;
265 }
266 if (flag)
267 {
268 System.out.printf("当前账户取款操作%d元成功。\r\n" + "当前账户余额为:%d元\r\n", number, Account_now.getAccountbalance());
269 }
270 PrintWriter out=null;
271 try
272 {
273 OutputStream f = new FileOutputStream("accountlist.txt",true);
274 out=new PrintWriter(f);
275 } catch (FileNotFoundException e)
276 {
277 e.printStackTrace();
278 }
279 out.printf("%s取款%d元\r\n",Account_now.getAccountID(),number);
280 out.printf("%s\r\n",Account_now.getOperatedate());
281 out.close();
282 }
283
284 public void deposit()
285 {
286 Scanner in = new Scanner(System.in);
287 System.out.printf(
288 "***************************************************************\r\n" + "欢迎%s使用中国工商银行自助柜员系统\r\n"
289 + "****************************************************************\r\n" + "请输入存款金额;\r\n"
290 + " \r\n" + "****************************************************************\r\n",
291 Account_now.getAccountname());
292 String number = in.nextLine();
293 if (Integer.valueOf(number).intValue() > 0)
294 {
295 Account_now.setAccountbalance(Account_now.getAccountbalance() + Integer.valueOf(number).intValue());
296 System.out.printf(
297 "***************************************************************\r\n" + "欢迎%s使用中国工商银行自助柜员系统\r\n"
298 + "****************************************************************\r\n" + "当前账户存款操作成功。\r\n"
299 + "当前账户余额为:%d元\r\n"
300 + "****************************************************************\r\n",
301 Account_now.getAccountname(), Account_now.getAccountbalance());
302 PrintWriter out=null;
303 try
304 {
305 OutputStream f = new FileOutputStream("accountlist.txt",true);
306 out=new PrintWriter(f);
307 } catch (FileNotFoundException e)
308 {
309 e.printStackTrace();
310 }
311 out.printf("%s存款%s元\r\n",Account_now.getAccountID(),number);
312 out.printf("%s\r\n",Account_now.getOperatedate());
313 out.close();
314 } else
315 {
316 GUI();
317 }
318 }
319
320 public void transfer()
321 {
322 String number1 = Account_now.getAccountID();
323 int balance = Account_now.getAccountbalance();
324 System.out.print("请输入转账账户;");
325 Scanner in = new Scanner(System.in);
326 String number2 = in.nextLine();
327 select_account(number2);
328 if (Account_now.getAccountID().equals(""))
329 {
330 System.out.println("该账户不存在");
331 } else
332 {
333 System.out.print("请输入转账金额;");
334 int number3 = in.nextInt();
335 if (number3 > balance)
336 {
337 System.out.println("账户余额不足");
338 } else
339 {
340 System.out.printf("请确认是否向*%s转账%d元。",Account_now.getAccountname().substring(1, Account_now.getAccountname().length()),number3);
341 in.nextLine();
342 String key =in.nextLine();
343 switch (key)
344 {
345 case "Y":
346 Account_now.setAccountbalance(Account_now.getAccountbalance() + number3);
347 balance -= number3;
348 System.out.printf("当前账户向*%s成功转账%d元。\r\n" +
349 "当前账户余额为:%d元\r\n",Account_now.getAccountname().substring(1, Account_now.getAccountname().length()),number3,balance);
350 PrintWriter out=null;
351 try
352 {
353 OutputStream f = new FileOutputStream("accountlist.txt",true);
354 out=new PrintWriter(f);
355 } catch (FileNotFoundException e)
356 {
357 e.printStackTrace();
358 }
359 out.printf("%s转账给%s%d元\r\n",number1,Account_now.getAccountID(),number3);
360 out.printf("%s\r\n",Account_now.getOperatedate());
361 out.close();
362 break;
363 case "N":
364 break;
365 }
366 }
367 }
368 select_account(number1);
369 Account_now.setAccountbalance(balance);
370 }
371
372 public void chang_password()
373 {
374 Scanner in=new Scanner(System.in);
375 System.out.print("请输入当前密码:");
376 String password=in.nextLine();
377 if(password.equals(Account_now.getAccountpassword()))
378 {
379 System.out.print("请输入修改密码:");
380 String password2=in.nextLine();
381 System.out.print("请输入确认密码:");
382 String password3=in.nextLine();
383 if(password2.equals(password3))
384 {
385 Account_now.setAccountpassword(password2);
386 System.out.println("当前账户密码修改成功");
387 PrintWriter out=null;
388 try
389 {
390 OutputStream f = new FileOutputStream("accountlist.txt",true);
391 out=new PrintWriter(f);
392 } catch (FileNotFoundException e)
393 {
394 e.printStackTrace();
395 }
396 out.printf("%s修改密码为%d\r\n",Account_now.getAccountID(),password2);
397 out.printf("%s\r\n",Account_now.getOperatedate());
398 out.close();
399 }
400 else
401 {
402 System.out.println("修改密码与确认密码不一致");
403 }
404 }
405 else
406 {
407 System.out.println("当前密码录入错误");
408 }
409
410 }
411
412 public void inquiry_balance()
413 {
414 System.out.printf("当前账户余额为:%d元\n",Account_now.getAccountbalance());
415 System.out.println("账户清单信息为:\n");
416 Scanner in=null;
417 try
418 {
419 in = new Scanner(Paths.get("accountlist.txt"));
420 } catch (IOException e)
421 {
422 e.printStackTrace();
423 }
424 while (in.hasNextLine())
425 {
426 System.out.println(in.nextLine());
427 }
428
429 }
430 }
AccountTest.java
1 package account;
2
3 /**
4 * @author 韩一祺
5 *
6 * 班级 信1705-3 学号 20173475
7 */
8 public class AccountTest
9 {
10 public static void main(String[] args)
11 {
12 AccountManager a = new AccountManager();
13 a.GUI();
14 }
15 }