如果您无法下载资料,请参考说明:
1、部分资料下载需要金币,请确保您的账户上有足够的金币
2、已购买过的文档,再次下载不重复扣费
3、资料包下载后请先用软件解压,在使用对应软件打开
自定义异常类,封装取款时发生异常得情况.定义银行账号类,当取款发生异常时抛出该异常,并写测试类测试.publicclassDepositExceptionextendsException{ﻫﻫpublicDepositException(){ﻫsuper();ﻫ//TODOAuto—generatedconstructorstub}ﻫpublicDepositException(Stringmessage){ﻫsuper(message);ﻫ//TODOAuto-generatedconstructorstubﻫ}ﻫ}ﻫﻫpackage、chinasofti、bank;/***银行账户得父类,定义共同得属性与方法*就是抽象类,定义子类得共同特征*authorwxh*ﻫ*/publicabstractclassAccount{//定义属性ﻫprivateStringaccountId;ﻫprivateStringpwd;ﻫprivatedoublebalance;//日志数组ﻫprivateString[]logInfo=newString[3];privateintlogIndex;ﻫ//无参数构造方法publicAccount(){//使用this调用本类重载得其她构造方法ﻫthis("0000”,"123456”,0、0);ﻫSystem、out、println("调用Account()");}publicAccount(StringaccountId,Stringpwd,doublebalance){super();ﻫthis、accountId=accountId;this、pwd=pwd;this、balance=balance;ﻫSystem、out、println(”调用Account(StringaccountId,Stringpwd,doublebalance)");ﻫ}ﻫ//getters与setterspublicStringgetAccountId(){ﻫreturnaccountId;}ﻫpublicStringgetPwd(){returnpwd;ﻫ}ﻫpublicvoidsetPwd(Stringpwd){this、pwd=pwd;ﻫ}ﻫﻫpublicdoublegetBalance(){returnbalance;ﻫ}publicvoidsetBalance(doublebalance){this、balance=balance;}ﻫ//存款,不使用异常//publicbooleandeposit(doubleamount){//booleanflag=true;ﻫ//if(amount〉0&&amount<=10000){ﻫ//Logger、log(this,”存款成功,金额:”+amount);//balance+=amount;//}else{//flag=false;ﻫ//}ﻫ//returnflag;//}ﻫ//存款,使用异常ﻫ//publicvoiddeposit(doubleamount){ﻫ////if(amount>0&&amount<=10000){//Logger、log(this,"存款成功,金额:"+amount);//balance+=amount;ﻫ//}else{////抛出异常//try{ﻫ//thrownewException("存款失败");//}catch(Exceptione){//System、out、println("存款金额不能为负数,重新输入。”);//}//}ﻫ////}ﻫ////存款,throws//publicvoiddeposit(doubleamount)throwsException{ﻫ//ﻫ//if(amount>0&&amount<=10000){//Logger、log(this,"存款成功,金额:"+amount);ﻫ//balance+=amount;//}else{////抛出异常ﻫ//thrownewException(”存款失败”);ﻫ//}ﻫ////}ﻫ////存款,throws,层层抛出publicvoiddeposit(doubleamount)throwsDepositException{ﻫﻫif(amount>0&&amount<=10000){ﻫLogger、log(this,"存款成功,金额:"+amount);balance+=amount;ﻫ}else{ﻫ//抛出异常try{ﻫthrownewDepositException("存款失败");}catch(DepositExceptione){Logger、log(this,"存款失败,金额:”+amount);ﻫthrowe;ﻫ}ﻫ}}ﻫ//存款,