您好,欢迎访问三七文档
当前位置:首页 > 临时分类 > 银行管理系统JAVA
1)Account.java类packagecom.etp;importjava.util.*;publicabstractclassAccount{protectedlongid;protectedStringpassword;protectedStringname;protectedStringpersonId;protectedStringemail;protecteddoublebalance;@Overridepublicbooleanequals(Objectobj){booleanrt=false;if(this==obj)rt=true;if(objinstanceofAccount){AccountanotherAcc=(Account)obj;if(this.id==anotherAcc.id)rt=true;}returnrt;}@OverridepublicinthashCode(){returnpassword.hashCode()+name.hashCode()+personId.hashCode()+email.hashCode();}@OverridepublicStringtoString(){returnid+;+password+;+name+;+personId+;+email+;+balance;}/**无参构造体*/publicAccount(){}/**有参构造体,用于初始化对象的必要属性*/publicAccount(longid,Stringpassword,Stringname,StringpersonId,Stringemail,doublebalance){this.setId(id);this.setPassword(password);this.setName(name);this.setPersonId(personId);this.setEmail(email);this.setBalance(balance);}/**存款方法*/publicvoiddeposit(doublemoney){balance+=money;}/**取款方法,抽象类,行为不确定,有储蓄账户和信用账户之分*@throwsBalanceNotEnoughException*/publicabstractvoidwithdraw(doublemoney)throwsBalanceNotEnoughException;/**属性的封装*/publicvoidsetId(longid){this.id=id;}publiclonggetId(){returnid;}publicvoidsetPassword(Stringpassword){this.password=password;}publicStringgetPassword(){returnpassword;}publicvoidsetName(Stringname){this.name=name;}publicStringgetName(){returnname;}publicvoidsetPersonId(StringpersonId){this.personId=personId;}publicStringgetPersonId(){returnpersonId;}publicvoidsetEmail(Stringemail){this.email=email;}publicStringgetEmail(){returnemail;}publicvoidsetBalance(doublebalance){this.balance=balance;}publicdoublegetBalance(){returnbalance;}}2)ATM.java类packagecom.etp;importjava.util.*;importjava.io.*;publicclassATM{privateBankbank;publicATM(){/*初始化Bank类,此时调用Bank的构造函数,其中默认的两个测试用户的信息被添加到Account类中*/bank=newBank();}publicstaticvoidmain(String[]args){ATMatm=newATM();atm.mainMenu();}privatevoidmainMenu(){booleanoutflag=true;do{System.out.println(ATM服务系统);System.out.println(****************);System.out.println(1.登录);System.out.println(2.开户);System.out.println(0.退出);System.out.println(****************);System.out.print(请选择操作:);Scannerscanner=newScanner(System.in);StringfirstChoice;do{firstChoice=scanner.next();if(firstChoice.matches(^[0-2]$)){break;}elseSystem.out.println(选择输入错误!);}while(true);booleanrt=true;out:do{switch(Integer.parseInt(firstChoice)){case1:/*进入登录界面或登录成功界面*/secondMenu();breakout;case2:/*开户,捕捉createAccount方法抛出的所有异常*/try{bank.createAccount();}catch(RegisterExceptione){System.out.println(e.toString());}rt=false;break;case0:rt=false;outflag=false;break;default:break;}}while(rt);}while(outflag);System.out.println(谢谢您的使用!);}/**登录成功后的二级菜单*/privatevoidsecondMenu(){Scannerscanner=newScanner(System.in);Accountaccount=null;out:dotry{/*输入卡号,输入exit可以直接退出系统*/System.out.print(输入卡号:);StringcardNo0;longcardNo;out1:do{cardNo0=scanner.next();if(cardNo0.equals(exit)||cardNo0.equals(EXIT)){breakout;}elseif(cardNo0.matches(^[0-9_]+$)){cardNo=Long.parseLong(cardNo0);breakout1;}elseSystem.out.println(请输入数字类型的ID!);}while(true);/*输入密码,输入exit可以直接退出系统*/System.out.print(密码:);Stringpassword=scanner.next();if(password.equals(exit)||password.equals(EXIT)){breakout;}account=bank.login(cardNo,password);breakout;}catch(LoginExceptione){System.out.println(e.toString());}while(true);if(account!=null){out:do{System.out.println(ATM操作界面);System.out.println(****************);System.out.println(1.存款操作);System.out.println(2.取款操作);System.out.println(3.查询余额);System.out.println(4.设置透支额度);System.out.println(5.统计银行总余额);System.out.println(6.查询本人信息);System.out.println(0.退出);System.out.println(****************);System.out.print(请选择操作:);scanner=newScanner(System.in);Stringsc;do{sc=scanner.next();if(sc.matches(^[0-6]+$)){break;}elseSystem.out.println(选择操作输入错误!);}while(true);switch(Integer.parseInt(sc)){case1:/*存款*//*最外层的循环用来询问用户是否继续。*/do{/*金额必须为数字类型,不能存取低于一元金额*/do{System.out.println(请输入存款金额:);Stringmoney=scanner.next();if(money.matches(^[0-9_]+$)){bank.deposit(account,Double.parseDouble(money));break;}elseSystem.out.println(金额必须为数字!);}while(true);System.out.println(存款结束!………………继续存款(Y)/结束存款(输入任意字符));Scanners=newScanner(System.in);Stringchoice=s.next();if(choice.equals(Y)||choice.equals(y))continue;elsebreak;}while(true);break;case2:/*取款*//*最外层的循环用来询问用户是否继续。*/do{/*金额必须为数字类型,不能存取低于一元金额*/do{System.out.println(请输入取款金额:);Stringmoney=scanner.next();if(money.matches(^[0-9_]+$)){try{bank.withdraw(account,Double.parseDouble(money));}catch(BalanceNotEnoughExceptione){//TODOAuto-generatedcatchblocke.printStackTrace();}break;}elseSystem.out.println(金额必须是数字类型!);}while(true);System.out.println(取款结束!………………继续取款(Y)/结束取款(输入任意字符));Scanners=newScanner(System.in);Stringchoice=s.next();if(choice.equals(Y)||choice.equals(y))continue;elsebreak;}while(true);break;case3:/*查看余额*/bank.showBalance(account);break;case4:/*设置透支额度*/bank.setCeiling(account);break;case5:/*统计银行总余额,调用Bank类中的totalBalance方法*/bank.totalBalance(account);break;case6:/*Account类中覆盖的toString方法使用*/System.out.println(account.toString());break;case0:/*退出的时候调用写入的方法,把更新的用户信息覆盖掉原来Accounts,txt中旧
本文标题:银行管理系统JAVA
链接地址:https://www.777doc.com/doc-3931702 .html