Package bank.accounts
Class Savings
java.lang.Object
bank.accounts.Savings
- All Implemented Interfaces:
Serializable
Class for savings accounts. Savings accounts have a minimum time period.
- See Also:
- Serialized Form
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected voidaddBalance(double amount)Add to the current balance (protected!).voidclose()Close savings account.voiddeposit(double amount)Savings accounts can only be initialized: they cannot be the object of deposit operations.booleandoubleReturns the current balance.longReturns the date of the deposit.intgetId()Return the deposit account id.doublegetRate()Return the account rate.intgetTime()Get the account's time period.toString()voidwithdraw(double amount)Withdrawals cannot be performed on savings accounts.
-
Constructor Details
-
Savings
- Parameters:
id- the account id.amount- the initial balance.rate- the account's interest rate.time- the account's time period.account- the associated bank account.
-
-
Method Details
-
getTime
public final int getTime()Get the account's time period.- Returns:
- the account's time period.
-
close
public void close()Close savings account. The balance of the account is added to the bank account associated with the savings account (which is then removed from the list of savings accounts). This method considers interest only after the time associated with the savings account has finished (otherwise, only the initial balance is deposited in the bank account). -
deposit
Savings accounts can only be initialized: they cannot be the object of deposit operations.- Parameters:
amount- the amount to be deposited (ignored).- Throws:
InvalidDepositException- since it is not possible to make deposits in savings accounts.
-
withdraw
Withdrawals cannot be performed on savings accounts.- Parameters:
amount- the amount to be withdrawn (ignored).- Throws:
InvalidWithdrawalException- since it is not possible to perform withdrawals from savings accounts.
-
toString
- Overrides:
toStringin classObject- See Also:
Object.toString()
-
addBalance
protected void addBalance(double amount)Add to the current balance (protected!).- Parameters:
amount- the amount to increase (or decrease).
-
getBalance
public double getBalance()Returns the current balance.- Returns:
- the current balance.
-
getCreationDate
public final long getCreationDate()Returns the date of the deposit.- Returns:
- the date of the deposit.
-
getRate
public final double getRate()Return the account rate.- Returns:
- the account rate
-
getId
public final int getId()Return the deposit account id.- Returns:
- the deposit account id
-
equals
- Overrides:
equalsin classObject- See Also:
Object.equals(java.lang.Object)
-