文件目录:
Account类:
package com.lukuan.javase.banking;
public class Account {
protected double balance;
public Account(double init_balance){
this.balance = init_balance;
}
public double getBalance() {
return balance;
}
public boolean deposit(double amt){
this.balance += amt;
return true;
}
public void withdraw(double amt) {
if(amt > balance){
throw new OverdraftException("支付失败,尚需", amt - balance);
}
this.balance -= amt;
}
}
SavingAccount类:
package com.lukuan.javase.banking;
public class SavingAccount extends Account{
private double interestRate;
public SavingAccount(double init_balance, double interestRate) {
super(init_balance);
this.interestRate = interestRate;
}
}
CheckingAccount类:
package com.lukuan.javase.banking;
public class CheckingAccount extends Account{
private Double overdraftProtection;
public CheckingAccount(double init_balance) {
super(init_balance);
}
public CheckingAccount(double init_balance, double overdraftProtection){
super(init_balance);
this.overdraftProtection = overdraftProtection;
}
@Override
public void withdraw(double amt) {
if(balance >= amt){
balance -= amt;
}else