欢迎来到天天文库
浏览记录
ID:52561228
大小:19.75 KB
页数:13页
时间:2020-03-28
《银行账户管理.docx》由会员上传分享,免费在线阅读,更多相关内容在应用文档-天天文库。
1、Account.javapackagecom.buaa.account;publicabstractclassAccount{privateintid;privateStringuserName;privatedoublebalance;publicstaticintCurrentID=100;//开户时调用的构造方法publicAccount(StringuserName,doublebalance){this.userName=userName;this.balance=balance;id=CurrentID++;}//
2、读取文件加载数据时用的构造方法publicAccount(intid,StringuserName,doublebalance){this.id=id;this.userName=userName;this.balance=balance;}publicstaticintgetCurrentID(){returnCurrentID;}publicstaticvoidsetCurrentID(intcurrentID){CurrentID+=currentID;}publicintgetId(){returnid;}public
3、voidsetId(intid){this.id=id;}publicStringgetUserName(){returnuserName;}publicvoidsetUserName(StringuserName){this.userName=userName;}publicdoublegetBalance(){returnbalance;}publicvoidsetBalance(doublebalance){this.balance=balance;}//存款publicvoiddeposit(doublemoney){
4、balance+=money;}//取款publicvoidwithdraw(doublemoney)throwsBalanceNotEnoughException{if(balance5、publicabstractdoubleinterest();}BalanceNotEnoughException.javapackagecom.buaa.account;publicclassBalanceNotEnoughExceptionextendsException{publicBalanceNotEnoughException(Stringmessage){super(message);}}Bank.javapackagecom.buaa.account;importjava.util.Collection;imp6、ortjava.util.LinkedHashMap;importjava.util.Map;publicclassBank{//所有的用户信息都存放在此map中privateMapmap=newLinkedHashMap();//开户,向map中加入一个Account对象publicvoidinsertAccount(Accountaccount){map.put(account.getId(),account);}//以数组的形式返回map中的所有数据pu7、blicAccount[]getAllAccount(){Collectionc=map.values();Account[]a=c.toArray(newAccount[0]);returna;}publicAccountgetAccount(intid){returnmap.get(id);}}Client.javapackagecom.buaa.account;importjava.io.BufferedReader;importjava.io.IOException;importjava.io.Inp8、utStreamReader;publicclassClient{/***@paramargs*/publicstaticvoidmain(String[]args){//TODOAuto-generatedmethodstubintselect=0;StringfileNa
5、publicabstractdoubleinterest();}BalanceNotEnoughException.javapackagecom.buaa.account;publicclassBalanceNotEnoughExceptionextendsException{publicBalanceNotEnoughException(Stringmessage){super(message);}}Bank.javapackagecom.buaa.account;importjava.util.Collection;imp
6、ortjava.util.LinkedHashMap;importjava.util.Map;publicclassBank{//所有的用户信息都存放在此map中privateMapmap=newLinkedHashMap();//开户,向map中加入一个Account对象publicvoidinsertAccount(Accountaccount){map.put(account.getId(),account);}//以数组的形式返回map中的所有数据pu
7、blicAccount[]getAllAccount(){Collectionc=map.values();Account[]a=c.toArray(newAccount[0]);returna;}publicAccountgetAccount(intid){returnmap.get(id);}}Client.javapackagecom.buaa.account;importjava.io.BufferedReader;importjava.io.IOException;importjava.io.Inp
8、utStreamReader;publicclassClient{/***@paramargs*/publicstaticvoidmain(String[]args){//TODOAuto-generatedmethodstubintselect=0;StringfileNa
此文档下载收益归作者所有