8.1 扩展如下的BankAccount类
新类CheckingAccount对每次存款和取款都收取1美元的手续费
class BankAccount(initialBalance:Double){
private var balance = initialBalance
def deposit(amount:Double) = {balance += amount;balance}
def withdraw(amount:Double) = {balance -= amount;balance}
}
class CheckingAccount(initialBalance:Double) extends BankAccount(initialBalance){
override def deposit(amount:Double) = {
super.deposit(amount - 1)
}
override def withdraw(amount:Double) = {
super.withdraw(amount + 1)
}
}
8.2 扩展一个练习的BankAccount类
新类SavingAccount每个月都有利息产生(earnMonthlyInterest方法被调用),
并且有每月三次免手续费存款或取款。在earnMonthlyInterest方法中重置交易计数。
class SavingAccount extends BankAccount{
private var num:Int = _
def earnMonthlyInterest()={
num = 3