Class SavingsAccount
java.lang.Object
bank.account.SavingsAccount
- All Implemented Interfaces:
Serializable
Class for savings accounts. Savings accounts have a minimum time period.
- See Also:
-
Constructor Summary
ConstructorsConstructorDescriptionSavingsAccount(int number, double amount, double rate, int duration, Account account) -
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.final booleandoubleReturns the current balance.final LocalDateReturns the date of the deposit.final intGet the account's duration.final intReturn the deposit account number.final doublegetRate()Return the account rate.toString()voidwithdraw(double amount) Withdrawals cannot be performed on savings accounts.
-
Constructor Details
-
SavingsAccount
- Parameters:
number- the account number.amount- the initial balance.rate- the account's interest rate.duration- the account's duration in days.account- the associated bank account.
-
-
Method Details
-
getDuration
public final int getDuration()Get the account's duration.- Returns:
- the account's duration.
-
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
-
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
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
-
getNumber
public final int getNumber()Return the deposit account number.- Returns:
- the deposit account number
-
equals
-