Package bank.accounts

Class Savings

java.lang.Object
bank.accounts.Savings
All Implemented Interfaces:
Serializable

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

    Constructors
    Constructor
    Description
    Savings​(int id, double amount, double rate, int time, 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.
    boolean
    equals​(Object depacc)
     
    double
    Returns the current balance.
    long
    Returns the date of the deposit.
    int
    Return the deposit account id.
    double
    Return the account rate.
    int
    Get the account's time period.
     
    void
    withdraw​(double amount)
    Withdrawals cannot be performed on savings accounts.

    Methods inherited from class java.lang.Object

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

    • Savings

      public Savings(int id, double amount, double rate, int time, Account account)
      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

      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:
      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

      public final boolean equals(Object depacc)
      Overrides:
      equals in class Object
      See Also:
      Object.equals(java.lang.Object)