1、pli abstract class Account 属性protetd on id;protecd Srig password;rteced Stringname;poteced Stng prsonI;otectedint acuntType; preced dbe blace; /构造方法pulic Accont() uper(); pblicAccunt(long d, String pswr, Sring n, Sting prsonId, in accoutType,duleblance) sper(); this。idi; this。passord = assord; ths。a
2、me=nam; thirsonId = prsonId; thiacuntype =cotpe; this.balance = ance;/gtX,sXx方法 ublclongetd() returnid;publc od setId(long ) ths.d i; pulic String gtPassd() reurnpasswor;pubic oid setPsord(Stg psord) hispassword =password; pblic StriggetNae() eturn ame;publc void setName(Sting nam) thisame name;ubli
3、c StringgetPernId() eturn ersoId; publivid ePonId(tin peonId) tis.peoI = persnd;ubi in gtcountTyp() reurn ccntType;pulic vidAcuntTp(int accountType) his。accotTyp acuTye; publc doublegtaance() retur baane;publcvi setBalane(dobbaace) thisbaance = baance;/* 存款 pblcvoidepost(double ony) balance +=moe;/*
4、 * 取款(取款方式由账户类型决定,所以设为抽象方法,相应的Accont类应设为抽象类) pulic abstract viwithdrw(doube oey);SainAcnt类pckage coqx;/* 储蓄账户类 ubic ass SavngAcou extend Accont /构造函数public Svingccout() sup(); plic SaingAont(loid, Singpasword, Srig name, Stinpersn,int accotType, dublbalance) uper(id,passwor, name,ersnI, aounType,bal
5、ac);/对父类的wthraw()实现puli vowthdaw(dubeme) if(alance oney) ystem。out.prinln(对不起,账户余额不足!);ele blance =mone; CrsitAccont类packge com。qx;* 信用账户类,增加一个信用额度ceiling属性pblc clas Creitccontexnds Accunt prate nt cng;/构造函数pulicCredicount() suer(); pulic CrditAccoun(lon , trig asswd, Strig name, Sting personId,int
6、accoutype, doble bnce, int ceilig) per(, psswr, nae, prnId, ccontTpe, balance);this.clin= cilig; /exx,eXx方法 publi nt geteiling() turn celing; pliid seCilng(int ceiig) thi.eilin = cing; /实现父类的withraw()pulvd ithaw(blemone) f(balance ceiling) money) ytem。outprintln(对不起,已超出您的信用额度!”); else balance = moey
7、; Bk类pakage om.x;mpo jaa.io.ferdeaer;imprt java。ioBuffeedWrite;imprtjaa.io.il;mportja.io。;mport javao.;impotjaa。io。;mport ja.io.IOExcepti;imort ava。ul.Propties;/ Bank类 编写Bank类,属性:1当前所有的账户对象的集合,存放在数组中当前账户数量方法:1.用户开户,需要的参数:id,密码,密码确认,姓名,身份证号码,账户类型,返回新创建的Acot对象的账号, 提示:用s1。eua(s2) 可以比较s1,s2两个字符串的值是否相等账户
8、类型是一个整数,为的时候表示储蓄账户,为1的时候表示信用账户2用户登录,参数:id,密码 返回登录账户的账号3用户存款,参数:d,存款数额,返回vod用户取款,参数:id,取款数额,返回vod.查询余额,参数:i,返回该账户的余额oube用户会通过调用Bank对象以上的方法来操作自己的账户,请分析各个方法需要的参数pulic las Bak pae ccout aconts = ew Acont20; ivate nt nmer;/账户数目rivate nt i 1001;/确定银行账号从10开始生成,即第一个账户的账号是100pubic Bak() accoun=new Acout2;/以后
9、不足时扩容。 nubr = 0; ufRde bufReader= nll;roeies rop=Sstem。tPrortis();Sring path=propsrperty(user。dir”); y bufRadernew uferedRed(new(new ,acounttt); Strings bufRede。eadine(); hie(s != null) trinstr= pit(,”); (tr4.equas(”) ccun sagc = ne Saigccount(Long。pasLng(str), roting(), str。oring(), st3tStrng(),Ing
10、rparseInt(tr4), DoubeparsDoule(str5); accountsnuer= saingAcc; else Accout crditAc wrediAcont(LongparseLn(st0), str。tSng(),str2oStrg(), tr3tong(),Iteger.parseI(st4), Double.prseDoube(st),50); acounsmber cditc; numbe +; +; s = bfRedrredLie(); atch (umerFormatExcepton e) / ODO Auogertedcatch blck eprin
11、ttkTrac(); th ( e) / OD Ao-generated catchblock e。rinStakTre(); tch(Ixcetin e) / TODOut-geneatd cath ok e.priStcTa(); inal try if(ufReader != null) bufReader。clos(); ctch (IOExepon e) TDO Autogenerad catch boc e。iackTac(); /geXx,sexxpublicAcout getccount() returnacunts;pblcvoidsetAcont(ccont account
12、s) ts。accunts =ccuts;publicint etNumber() retun numbe;pblc oidstumber(int nmbe) numbe = numr; pubic in eId() rtur i; pulic vdtd(in i) tis = id; 开户 /pli ccounopeAcont(String asw,ingpasswd, Strng name, String pson, it tpe) /创建一个新账户 ccountacoun =null;判断两次密码是否一致 if(psswd.eual(passw2)/若一致,再判断账户类型(根据type的
13、值) if(type ) /可令开始余额为,信用额度为5000 count ewCreditAccout(id, swd1,ame, prsod,ty, 500); else accont new avigAccout(,assw1,nme,perId, typ, 0); /将账户存入账户数组accs中 /判断是否超出存储空间 if(umber= acoun.length) /扩容 Accout newAconts = e Acutccus。lngh*2; /py原来的相关数据 ysm。aacoy(accuns, 0,newAccount, ,contlenth); /将newcous赋给ac
14、ouns accons = ewAccout; ccntsnumber acount; else ccontsnumber =ccount; Sysem.ou。prntl(开户成功!账户信息见下”); Sys。o。pintln(您的卡号为:+id+”n+”您的密码为:+passd1”您的户名为:+nmn” 您的身份证号为:”+esoId+n您的账户类型为:+type+n”); ccont。accuType= typ; numb+; d+; trn acount;/此时开户成功 else System.utprintl(对不起!您两次密码输入不匹配,开户失败!!); returnnull;/此时
15、开户失败/ 保存数据 pblic id vActDat()BufereWit bufWrite=nu;try Popetepops=Syemgeopertie(); Stng path=props。getPropr(ueir); bufWrier=ne Buffredrier(ew (new ,”coun。txt); for(ini 0;i accouts。legth;i+) /若存在账户 f(acounti!= ull) /写入账户信息到accuxt burer。rite(ccountsi.id+”,); bufiter。wri(acountsi。getasswor()+”, bufWerw
16、ie(accuntsigeame()+”,); uWriter。write(ccons。gePersonId()+, ufrier。rite(accosi。gAccuntype()+,”); ufWiterwrte(DubletoSring(accounti。etBalance(); bufit.nein(); lse reak; bfWriter。fuh();/清空缓存中的内容 ath (IOException ) /TODO togneated cchbck e.prtStackTrace(); fnally ry f(buWrier!=null) bufWrte。cose(); cah
17、(Oxcption e) / ODO Ao-genertedath block prinSckTrce(); /* * 登录验证 pubiAccu verifyAcun(long id, Strngpassword) cconaccun = nl; fo(it i 0;i accousleth;i+) /若存在账户 f(acons != nll) /验证id号和pswrd if(i=acoui。tId() &aoqus(accountsi.getPasword() accunt=autsi; rek; bak; rtrcunt; * 转账验证(方法的重载) * ubic Acount vriA
18、count(ong ) Account acount = ul;o(i i = 0;i acounts。 /若存在账户i(acci !=nul) /验证id号和assword f(d = accuntsi。gtId() account = acuntsi; brek; else bra; reur accun;* 转账*/ publi vod transfercun(Acount account1, Accont ccu2, obeoey)acont1。ithdaw(money); accoun2poit(ey); */ pubic void deosit(Accoun account,dobl moey)aount.deposit(oey); /* 取款 puliod withdr(ccount account, doble moey) acut.itdaw(one);A类packa coqx;imotio.BufferReader;impotjv。i.uffredrie;imprt aa。ioile;imort jaa.io。impot java.o.;po java。il.Proprts;importjvautlScanner;