publicvoidmain(){int a =0;System.out.println("***************");System.out.println("***欢迎使用ATM***");System.out.println("***************");System.out.println("请输入卡号");String user =newScanner(System.in).next();System.out.println("请输入密码");String pwd =newScanner(System.in).next();for(int i =0; i <this.list.size(); i++){if(this.list.get(i).getAccount().equals(user)&&this.list.get(i).getPassword().equals(pwd)){
a =1;System.out.println("-->>密码正确");
atm = list.get(i);secondMain();break;}}if(a ==0){System.out.println("密码错误");main();return;}}privatevoidsecondMain(){int a =0;while(a !=6){System.out.println("*********************");System.out.println("**请输入你想要操作的类型**");System.out.println("** 1.余额查询 2.取款 **");System.out.println("** 3.存款 4.转账 **");System.out.println("** 5.打印 6.退卡 **");System.out.println("*** 7.查询转账信息 ***");System.out.println("***************");
a =newScanner(System.in).nextInt();switch(a){case1:yue();break;case2:getMoney();break;case3:saveMoney();break;case4:transfer();break;case5:print();break;case6:exit();break;case7:askTransferInfo();break;}}}
创建各种功能 取款(test)、存款(test)、、、、、
privatevoidyue(){System.out.println("你的余额是:"+ atm.getBalance());}privatevoidgetMoney(){FileWriter out =null;BufferedWriter bw =null;try{System.out.println("请输入你要取款金额");double money =newScanner(System.in).nextDouble();
atm.setBalance(atm.getBalance()- money);
out =newFileWriter("account.txt");
bw =newBufferedWriter(out);if(list.indexOf(atm)>-1){
list.set(list.indexOf(atm), atm);System.out.println("取钱成功!!你的余额是"+ atm.getBalance());for(int i =0; i < list.size(); i++){
bw.write(list.get(i).getAccount()+","+list.get(i).getPassword()+","+ list.get(i).getBalance()+","+ list.get(i).getBankName()+","+ list.get(i).getName());
bw.newLine();}}}catch(IOException e){
e.printStackTrace();}finally{try{if(bw !=null)
bw.close();if(out !=null)
out.close();}catch(IOException e){
e.printStackTrace();}}}privatevoidsaveMoney(){FileWriter out =null;BufferedWriter bw =null;try{System.out.println("请输入你要存款金额");double money =newScanner(System.in).nextDouble();
atm.setBalance(atm.getBalance()+ money);
out =newFileWriter("account.txt");
bw =newBufferedWriter(out);if(list.indexOf(atm)>-1){
list.set(list.indexOf(atm), atm);System.out.println("存款成功!!你的余额是"+ atm.getBalance());for(int i =0; i < list.size(); i++){
bw.write(list.get(i).getAccount()+","+list.get(i).getPassword()+","+ list.get(i).getBalance()+","+ list.get(i).getBankName()+","+ list.get(i).getName());
bw.newLine();}}}catch(IOException e){
e.printStackTrace();}finally{try{if(bw !=null)
bw.close();if(out !=null)
out.close();}catch(IOException e){
e.printStackTrace();}}}privatevoidtransfer(){int a =0;FileWriter out =null;BufferedWriter bw =null;System.out.println("请输入你要转账的卡号");String user =newScanner(System.in).next();for(int i =0; i < list.size();i++){Atm atm1 = list.get(i);if(atm1.getAccount().equals(user)&&!atm1.getAccount().equals(atm.getAccount())){
a =1;System.out.println("请输入你要转账的金额");double money =newScanner(System.in).nextDouble();if(atm.getBalance()- money <0){System.out.println("余额不足");}else{
atm.setBalance(atm.getBalance()- money);
atm1.setBalance(atm1.getBalance()+ money);System.out.println("转账成功,你的余额是"+ atm.getBalance());String data = atm1.getName()+ money +" "+ atm1.getBankName();
transferInfo.add(data);try{
out =newFileWriter("account.txt");
bw =newBufferedWriter(out);for(int j =0; j < list.size(); j++){
bw.write(list.get(j).getAccount()+","+list.get(j).getPassword()+","+ list.get(j).getBalance()+","+ list.get(j).getBankName()+","+ list.get(j).getName());
bw.newLine();}}catch(IOException e){
e.printStackTrace();}finally{try{if(bw !=null)
bw.close();if(out !=null)
out.close();}catch(IOException e){
e.printStackTrace();}}break;}}else{
a =0;}}if(a ==0){System.out.println("输入错误");transfer();}}privatevoidprint(){System.out.println("文件保存路径 m.txt");FileWriter out =null;BufferedWriter bw =null;try{
out =newFileWriter("m.txt");
bw =newBufferedWriter(out);for(Atm atm :
list){
bw.write(atm.getAccount()+","+atm.getPassword()+","+ atm.getBalance()+","+ atm.getBankName()+","+ atm.getName());
bw.newLine();}}catch(IOException e){
e.printStackTrace();}finally{try{if(bw !=null)
bw.close();if(out !=null)
out.close();}catch(IOException e){
e.printStackTrace();}}}privatevoidexit(){System.out.println("请保管好你的卡片");System.exit(0);}privatevoidaskTransferInfo(){for(String s :
transferInfo){System.out.println(s);}}