以银行帐户类BankAccount作为超类,创建一个支票帐户类CheckingAccount。
要求:
1.增加一个表示交易数量的实例变量transactionCount
2.增加一个新方法deductFees,表示从帐户中扣除一定税款的操作,具体规则为交税时若交易数量超过3笔,超出的每笔交易扣除2元税款
3.提示:必要的话需要覆盖存、取款的方法
public class BankAccount {
private String id;
private double balance;
public BankAccount(String id)
{
this.id = id;
}
public void deposit(double amount)
{
balance += amount;
}
public void withdraw(double amount)
{
balance -= amount;
}
public String getId()
{
return id;
}
public double getBalance()
{
return balance;
}
}
public class CheckingAccount extends BankAccount{
private int transactionCount;
public CheckingAccount(String id)
{
super(id);
}
public void deposit(double amount)
{
super.deposit(amount);
transactionCount++;
}
public void withdraw(double amount)
{
super.withdraw(amount);
transactionCount++;
}
public void deductFees()
{
if(transactionCount>3){
double i = (transactionCount - 3)*2;
super.withdraw(i);
}
transactionCount = 0;
}
public static void main(String[] args) {
// TODO Auto-generated method stub
CheckingAccount account = new CheckingAccount("B0001");
account.deposit(1000);
account.deposit(1000);
account.deposit(1000);
account.deposit(1000);
account.withdraw(1000);
account.withdraw(1000);
account.deductFees();
System.out.println(account.getBalance());
System.out.println(account.transactionCount);
}
}