类的继承关系和多态性

现有一个父类 ACcount 表示银行账户。银行账户又分为储蓄账户
( SavingAccount )和支票账户( CheckingAccount )。两种账户的区别是计算活期年利息的方式不同:
储蓄账户:利率为:0.0036
支票账户:¥0一¥20000利率为:0.0036¥20000一¥40000利率为:0.0037
¥40000一¥80000利率为:0.0038¥80000以上利率为:0.0040
计算利息额公式为:利息=余额 x 利率
要求:
(1)为 SavingACCount 和 CheckingACCount 提供参数为( String idCard , double balance )的构造方法,在该构造方法中用 ACCount 的构造方法。
(2)根据以上描述在 SavingACCount 和 CheckingACCount 中重写 getnterest 方法


public class ACcount {
    protected String idCard;
    protected double balance;

    protected double rate;

    protected double interest;

    public ACcount(String idCard, double balance) {
        this.idCard = idCard;
        this.balance = balance;
    }

    public double getInterest() {
        return balance * rate;
    }
}




///////////////////////////////////////////////////////////////////////////////////////


public class SavingAccount extends ACcount {
    public SavingAccount(String idCard, double balance) {
        super(idCard, balance);
    }

    @Override
    public double getInterest() {
        return balance * 0.0036;
    }
}


///////////////////////////////////////////////////////////////////////////////////////


public class CheckingAccount extends ACcount {
    private static final double BALANCE_2W = 20000;
    private static final double BALANCE_4W = 40000;
    private static final double BALANCE_8W = 80000;

    public CheckingAccount(String idCard, double balance) {
        super(idCard, balance);
    }

    @Override
    public double getInterest() {
        if (balance < BALANCE_2W) {
            rate = 0.0036;
        } else if (BALANCE_2W <= balance && balance < BALANCE_4W) {
            rate = 0.0037;
        } else if (BALANCE_2W <= balance && balance < BALANCE_4W) {
            rate = 0.0038;
        } else if (BALANCE_4W <= balance && balance < BALANCE_8W) {
            rate = 0.0040;
        }
        return balance * rate;
    }
}

若是有帮助,请采纳

这种题目没有100做不了

哈哈,我只要八十