以银行帐户类BankAccount作为超类,创建一个支票帐户类CheckingAccount。

以银行帐户类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);

	}
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

拔刀能留住落樱嘛.

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值