Java Reference
In-Depth Information
36 */
37
public void
deductFees()
38 {
39
if
(transactionCount > FREE_TRANSACTIONS)
40 {
41
double
fees = TRANSACTION_FEE *
42 (transactionCount -
FREE_TRANSACTIONS);
43
super
.withdraw(fees);
44 }
45 transactionCount =
0
46 }
47
48
private int
transactionCount;
49
50
private static final int
FREE_TRANSACTIONS
=
3
;
51
private static final double
TRANSACTION_FEE
=
2.0
;
52 }
458
459
ch10/accounts/SavingsAccount.java
1 /**
2
An account that earns interest at a fixed rate.
3 */
4
public class
SavingsAccount
extends
BankAccount
5 {
6 /**
7
Constructs a bank account with a given interest rate.
8 @param rate
the interest rate
9 */
10
public
SavingsAccount(
double
rate)
11 {
12 interestRate = rate;
13 }
14
15 /**
16
Adds the earned interest to the account balance.
17 */
18
public void
addInterest()
19 {
20
double
interest = getBalance() *
interestRate /
100
;