public class BankAccount
extends java.lang.Object
Constructor and Description |
---|
BankAccount(java.lang.String ownerName,
int initialBalance)
This constructor stores the name of the owner and the initial balance of the bank account.
|
Modifier and Type | Method and Description |
---|---|
double |
computeBalanceAfterInterest(int periods,
double rate)
Computes the balance after applying a given interest rate for a number of periods.
|
int |
getBalance()
Provides the current balance of this bank account.
|
java.lang.String |
getOwner()
Provides the owner associated with this bank account, that was provided during the creation
of this bank account object.
|
java.util.List<Transaction> |
getTransactions()
Provides the list of transactions that involve this bank account.
|
void |
withdrawMoney(int amount)
Performs the withdraw money transaction on this bank account.
|
public BankAccount(java.lang.String ownerName, int initialBalance)
ownerName
- the name of the owner of the new bank accountinitialBalance
- the initial balance of the new bank accountpublic double computeBalanceAfterInterest(int periods, double rate) throws java.lang.IllegalArgumentException
It is assumed that interest is paid at the end of each period, and that the interest is compounded.
The formula used for this is: balance × (1 + rate)periods
Example: a bank account with a balance of 100 will become 110.25 after applying an interest of 0.05 for two periods.
periods
- the number of periods in which interest should be appliedrate
- the interest rate applied in every periodjava.lang.IllegalArgumentException
- if periods is smaller than zeropublic int getBalance()
public java.lang.String getOwner()
public java.util.List<Transaction> getTransactions()
public void withdrawMoney(int amount) throws java.lang.IllegalArgumentException
amount
- the amount of money to withdraw from the bank accountjava.lang.IllegalArgumentException
- if the amount exceeds the current balance of the account