Package bank
Class Account
java.lang.Object
bank.Account
- All Implemented Interfaces:
Serializable,Comparable<Account>
This class represents the relationship between a bank and its customers
(account holders). An account belongs to one or more holders. Each account
has one current account and 0 (zero) or more savings accounts.
- See Also:
- Serialized Form
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidAdd an account holder.voidaddSavingsAccount(double amount, double rate, int time)booleanVerifies whether an account can be removed.intCompares account ids.voidcreateSavingsAccount(double amount, double rate, int time)doublevoiddeposit(double amount)Makes a deposit in the current account.booleanTwo accounts are considered equal when they have the same account number.intgetId()holders()Returns the holders of the account.voidremoveSavingsAccount(Savings account)Remove a given savings account.savingsAccount(int id)Returns the savings accounts associated with the bank account.Returns the savings accounts associated with the bank account.toString()String representation of the account: presents the account number and the total balance.doubleReturns the total balance for the account.voidwithdraw(double amount)Performs a withdrawal.
-
Constructor Details
-
Account
public Account(int id, double amount)- Parameters:
id- account idamount- initial amount for the current account.
-
-
Method Details
-
getId
public final int getId()- Returns:
- the account number.
-
compareTo
Compares account ids.- Specified by:
compareToin interfaceComparable<Account>
-
equals
Two accounts are considered equal when they have the same account number. -
deposit
Makes a deposit in the current account.- Parameters:
amount- the amount to be deposited.- Throws:
InvalidDepositException- if it is not possible to make the deposit.NegativeAmountException- if the amount is not positive.
-
withdraw
public void withdraw(double amount) throws InvalidWithdrawalException, NegativeAmountException, BalanceTooLowExceptionPerforms a withdrawal.- Parameters:
amount- the amount to be withdrawn.- Throws:
InvalidWithdrawalException- if it is not possible to withdraw the intended amount.NegativeAmountException- if the amount is not positive.BalanceTooLowException
-
currentAccountBalance
public double currentAccountBalance()- Returns:
- the amount in the current account.
-
totalBalance
public double totalBalance()Returns the total balance for the account. This balance includes the current account balance and the balances of all the savings accounts. The following implementation uses an implicit iterator, but the same actions could be performed using an explicit one.- Returns:
- the account balance.
-
holders
Returns the holders of the account.- Returns:
- a list with the holders of the account.
-
addSavingsAccount
public final void addSavingsAccount(double amount, double rate, int time) throws InvalidWithdrawalException, NegativeAmountException, BalanceTooLowException- Parameters:
amount-rate-time-- Throws:
BalanceTooLowExceptionNegativeAmountExceptionInvalidWithdrawalException
-
createSavingsAccount
public void createSavingsAccount(double amount, double rate, int time) throws InvalidWithdrawalException, NegativeAmountException, BalanceTooLowException- Parameters:
amount-rate-time-- Throws:
BalanceTooLowExceptionNegativeAmountExceptionInvalidWithdrawalException
-
savingsAccount
Returns the savings accounts associated with the bank account.- Parameters:
id-- Returns:
- the savings account
- Throws:
NoSuchSavingsAccountException
-
savingsAccounts
Returns the savings accounts associated with the bank account.- Returns:
- a list of savings deposits or null (if there are no savings deposits.
-
removeSavingsAccount
Remove a given savings account.- Parameters:
account- the savings account to be removed.
-
addHolder
Add an account holder.- Parameters:
holder- the holder to be added.
-
canBeRemoved
public final boolean canBeRemoved()Verifies whether an account can be removed. An account can be removed only when its total balance is 0 (zero).- Returns:
- true, if the account can be removed; false, otherwise.
-
toString
String representation of the account: presents the account number and the total balance.
-