regularaccount.java

来自「国外的数据结构与算法分析用书」· Java 代码 · 共 47 行

JAVA
47
字号
package Accounts;

import People.Customer;
import dslib.list.LinkedListUos;
import dslib.base.FormatUos;

/**	A regular account that allows deposits and keeps a log of transactions on the account. */
public abstract class RegularAccount extends Account
{
	/**	A collection of transactions. */
	protected LinkedListUos log;

	/**	Constructs a RegularAccount from a Customer and an account number. */ 
	public RegularAccount(Customer c, int n)
	{
		super(c, n);
		log = new LinkedListUos();
	}

	/**	Deposit 'a' dollars into the account. */
	public void deposit(float a)
	{
		balance += a;
	}
	
	/**	Add a transaction to the collection of transactions. */
	public void logTrans(int d, String des, float amt, float loc)
	{
		Transaction t = new Transaction(d, des, amt, loc);
		log.insertLast(t);
	}
	
	/**	Generate a listing of all the transactions that are currently in the transaction log. */
	public String generateMonthlyStmt()
	{
		String result = "\nTransactions for account " + number 
				+ " with owner " + owner.name() + ":" + Transaction.header();
		log.goFirst();
		while (!log.after())
		{	
			result += log.item().toString();
			log.goForth();
		}
		return result + "\nFinal balance is $" + FormatUos.withDecimals(balance, 2) + "\n";
	}
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?