码迷,mamicode.com
首页 > 其他好文 > 详细

2.建立exception包,建立Bank类,类中有变量double balance表示存款,Bank类的构造方法能增加存款,Bank类中有取款的发方法withDrawal(double dAmount),当取款的数额大于存款时,抛出InsufficientFundsException,取款数额为负数,抛出NagativeFundsException,

时间:2016-05-28 17:41:57      阅读:271      评论:0      收藏:0      [点我收藏+]

标签:

public class Bank {

    Double qian=0.0;
    
    double newBank(double a)
    {
        qian=qian+a;
        return qian;
    }
    double withDrawal(double dAmount) throws Exception
    {
        if(dAmount>qian)
        {
            throw new Exception("InsufficientFundsException");
            
        }
        if(dAmount<0)
        {
            throw new Exception("NagativeFundsException");
            
        }
        qian=qian-dAmount;
        return qian;
    }
   public static void main(String[] args) throws Exception {
       Bank a=new Bank();
       a.newBank(100);
       a.withDrawal(-50);
       
    
}
    

}

技术分享

   public static void main(String[] args) throws Exception {
       Bank a=new Bank();
       a.newBank(100);
       a.withDrawal(150);
       
    
}

技术分享

2.建立exception包,建立Bank类,类中有变量double balance表示存款,Bank类的构造方法能增加存款,Bank类中有取款的发方法withDrawal(double dAmount),当取款的数额大于存款时,抛出InsufficientFundsException,取款数额为负数,抛出NagativeFundsException,

标签:

原文地址:http://www.cnblogs.com/wenwen123/p/5537687.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!