// ATMSavingsAccount.java // Solution to Short Assignment 11 by THC. // Defines a class of ATM savings account. // The first two withdrawals are free, and then they cost $1.50 in each period. // Deposits are always free. public class ATMSavingsAccount extends SavingsAccount { private static final int FREE_WITHDRAWALS = 2; private static final double TRANSACTION_FEE = 1.50; private int withdrawals; // Constructor that sets rate. public ATMSavingsAccount(double rate) { super(rate); withdrawals = 0; } // Constructor that sets rate and initial balance. public ATMSavingsAccount(double rate, double initialAmount) { super(rate, initialAmount); withdrawals = 0; } // Withdraw amount from account, but count as a withdrawal. public void withdraw(double amount) { super.withdraw(amount); withdrawals++; } // Add the periodic interest, but then subtract withdrawal fees. public void addPeriodicInterest() { super.addPeriodicInterest(); if (withdrawals > FREE_WITHDRAWALS) super.withdraw(TRANSACTION_FEE * (withdrawals - FREE_WITHDRAWALS)); withdrawals = 0; } }