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

}

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

   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,

相关文章:

  • 2021-06-16
  • 2021-12-02
  • 2022-12-23
  • 2022-12-23
  • 2021-11-17
  • 2021-09-08
  • 2022-01-08
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-07-23
  • 2021-06-26
  • 2021-11-17
  • 2022-12-23
  • 2021-11-17
相关资源
相似解决方案