Using Inheritance

For this Programming activity, you will create the SavingAccount class, which inherits directly from the BankAccount class.

The SavingsAccountclass inherits from the version ofthe BankAccountclass

in which the balanceis declared to be private.The SavingsAccountsubclass

adds an annual interestRateinstance variable,as well as supporting meth-

ods to access,change,and apply the interest rate to the account balance.

Instructions

Copy the source files in the Programming Activity 1 directory for this chap-

When you have completed the six tasks,load,compile,and run the Teller

application (Teller.java),which you will use to test your SavingsAccount

class.When the Teller application begins,you will be prompted with a dia-

log box for a starting balance.Ifyou press “Enter”or the “OK”button with-

out entering a balance, the Teller application will use the default

constructor to instantiate a SavingsAccountobject.Ifyou enter a starting

balance,the Teller application will prompt you for an interest rate and will

instantiate a SavingsAccountobject using the overloaded constructor.Once

the SavingsAccountobject has been instantiated,the Teller application will

open the window shown in Figure10.10,which provides buttons you can

use to call the SavingsAccountmethods to test your code.

Below the buttons is a ledger that displays the current state ofthe savings

account.As you click on the various buttons,the ledger will display the

operation performed and the values ofthe balance and the interest rate

when that operation is complete. The operations performed by each button are already coded for you and

are the following:

IChange Interest Rate—prompts for a new interest rate and calls

your set Interest Rate method

IApply Interest—calls your apply Interest method I Deposit—prompts for the deposit amount and calls the deposit



method inherited from BankAccount I Withdraw—prompts for the withdrawal amount and calls the withdraw method inherited from BankAccount





answer the following questions.

1. Explain why the Teller application can call the withdraw and deposit methods using a SavingsAccount object reference, even though we did not define these methods.

2. Explain why your applyInterest method in the SavingAccount class needs to call the deposit method of the BankAccount class.
Powered by