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

    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);
           
        
    }

  • 相关阅读:
    yii主题
    aptana studio 使用技巧整理
    big database url
    yii表单输入元素
    下载,和scp上传问题
    对缓存的思考——提高命中率
    php用户名密码
    openx -书表添加字段
    搜索
    python——常用模块2
  • 原文地址:https://www.cnblogs.com/wenwen123/p/5537687.html
Copyright © 2011-2022 走看看