Class SavingsAccount

java.lang.Object
bank.account.SavingsAccount
All Implemented Interfaces:
Serializable

public class SavingsAccount extends Object
Class for savings accounts. Savings accounts have a minimum time period.
See Also:
  • Constructor Summary

    Constructors
    Constructor
    Description
    SavingsAccount(int number, double amount, double rate, int duration, Account account)
     
  • Method Summary

    Modifier and Type
    Method
    Description
    protected void
    addBalance(double amount)
    Add to the current balance (protected!).
    void
    Close savings account.
    void
    deposit(double amount)
    Savings accounts can only be initialized: they cannot be the object of deposit operations.
    final boolean
     
    double
    Returns the current balance.
    final LocalDate
    Returns the date of the deposit.
    final int
    Get the account's duration.
    final int
    Return the deposit account number.
    final double
    Return the account rate.
     
    void
    withdraw(double amount)
    Withdrawals cannot be performed on savings accounts.

    Methods inherited from class Object

    clone, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
  • Constructor Details

    • SavingsAccount

      public SavingsAccount(int number, double amount, double rate, int duration, Account account)
      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

      public void deposit(double amount) throws InvalidDepositException
      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

      public void withdraw(double amount) throws InvalidWithdrawalException
      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

      public String toString()
      Overrides:
      toString in class Object
      See Also:
    • 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 LocalDate 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

      public final boolean equals(Object o)
      Overrides:
      equals in class Object
      See Also: