⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 account.java

📁 噶额外噶外骨骼感广泛高热感 就 啊啊
💻 JAVA
字号:
package itso.bank.model;

import itso.bank.exception.InsufficientFundsException;
import java.io.Serializable;
import java.util.Vector;
import java.util.TreeSet;
import java.math.BigDecimal;

/**
 * The banking account model class.
 * 
 * @author Fabio Ferraz
 */

public class Account implements Comparable, Serializable
{
	// The account business data
	private String id;
	private String type;
	private BigDecimal balance;

	// constructor
	public Account() { super(); }
	public Account(String accountid) {
		setId(accountid);
		setBalance( new BigDecimal(0.00) );
	}
	
	// getters
	public String getId() { return id; }
	public String getType() { return type; }
	public java.math.BigDecimal getBalance() { return balance; }

	// setters
	public void setId(String id) { this.id = id; }
	public void setType(String type) { this.type = type; }
	public void setBalance(java.math.BigDecimal balance) { this.balance = balance; }
	
	// business methods
	public BigDecimal deposit(BigDecimal amount) {
		setBalance( getBalance().add(amount) );
		return getBalance();
	}
	public BigDecimal withdraw(BigDecimal amount) throws InsufficientFundsException {
		if ( getBalance().compareTo(amount) == -1 ) 
			throw new InsufficientFundsException();
		setBalance( getBalance().subtract(amount) );		
		return getBalance();
	}
	
	// compare two Account: required to enable sorting of accounts
	public int compareTo(Object anObject) {
		Account other = (Account) anObject;
		return getId().compareTo(other.getId());
	}

	// nice output
	public String toString() {
		return "Account "+ id +" "+ type +" "+ balance;
	}
}

⌨️ 快捷键说明

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