UNB/ CS/ David Bremner/ teaching/ old/ cs1083/ java/ SavingsAccount.java
import java.math.BigDecimal;
public class SavingsAccount extends DecimalAccount {

    private BigDecimal interestRate;

    public SavingsAccount(int permille, long initialDollars, int initialCents) {
        super(initialDollars, initialCents);
        interestRate = new BigDecimal(permille).scaleByPowerOfTen(-3);
    }
    public SavingsAccount(BigDecimal rate)
    {
        interestRate = rate;
    }

    public void addInterest() {
        BigDecimal interest = getBalance().multiply(interestRate);
        deposit(interest);
    }

    public static void main(String[] args)
    {
        SavingsAccount account = new SavingsAccount(50,100,00);

        // compute and add interest for one period
        account.addInterest();
        System.out.println("Balance after year 1 is $"
                           + account.getBalance());

        // add interest again
        account.addInterest();
        System.out.println("Balance after year 2 is $"
                           + account.getBalance());
   }

}