Write a class SavingsAccount that is similar to the BankAccount class, except that it has an added instance variable interest. Supply a constructor that sets both the initial balance and the interest rate. Supply a method addInterest (with no explicit parameter) that adds interest to the account. Write a SavingsAccountTester class that constructs a savings account with an initial balance of $1,000 and an interest rate of 10%. Then apply the addInterest method and print the resulting balance. Also compute the expected result by hand and print it.

Complete the following files:

SavingsAccount.java

/** A savings account has a balance that can be changed by deposits and withdrawals. */ public class SavingsAccount { private double balance; private double interestRate; /** Constructs a savings account with a zero balance */ public SavingsAccount() { balance = 0; interestRate = 0; } /** Constructs a savings account with a given balance @param initialBalance the initial balance @param rate the interest rate in percent */ public SavingsAccount(double initialBalance, double rate) { balance = initialBalance; interestRate = rate; } /** Deposits money into the savings account. @param amount the amount to deposit */ public void deposit(double amount) { double newBalance = balance + amount; balance = newBalance; } /** Withdraws money from the savings account. @param amount the amount to withdraw */ public void withdraw(double amount) { double newBalance = balance - amount; balance = newBalance; } /** Gets the current balance of the savings account. @return the current balance */ public double getBalance() { return balance; } /** . . . */ public void addInterest() { . . . } }

SavingsAccountTester.java

/** Tests the savings account class. */ public class SavingsAccountTester { public static void main(String[] args) { SavingsAccount momsSavings = new SavingsAccount(1000, 10); momsSavings.addInterest(); momsSavings.addInterest(); momsSavings.addInterest(); momsSavings.addInterest(); momsSavings.addInterest(); System.out.print("Balance: "); System.out.println(. . .); System.out.println("Expected: . . ."); } }

SavingsAccountTester2.java