Question: Consider the class hierarchy used in Chapter 9 Part II Exercise 1: Bank Account Checking Account Your task is to derive another subclass called SavingAccount


Consider the class hierarchy used in Chapter 9 Part II Exercise 1: Bank Account Checking Account Your task is to derive another subclass called SavingAccount to reflect the following hierarchy: Bank Account CheckingAccount SavingAccount TI Define the new subclass SavingAccount as follows: It has an instance variable interest Rate of type double A constructor to first call the constructor in the superclass and then initialize interestRate. Override the deposit() method so that the customer receives a credit equal to the product of interestRate and the amount that he deposited. Override the toString() method so that it returns the following string Account Number=the account number Balance the balance Interest Rate=the interest rate A method called annualCredit() that is called at the end of the year. This method gives the customer an additional credit according to the following rules: If balance is less or equal 1000, the customer receives a credit equal to the product of interestRate and balance If balance is less or equal 5000, the customer receives a credit equal to the product of twice the interestRate and balance, Else (balance > 5000), the customer receives a credit equal to the product of three times the interestRate and balance. Write a Java program to test your new class like this SavingAccount savingAccount = new SavingAccount(879101,0,0,04), I savingAccount.deposit(500); savingAccount withdraw(500); savingAccount deposit(1500), savingAccount deposit(500); savingAccount withdraw(500); savingAccount deposit(5000). savingAccount deposit(500), savingAccount annualCredit: System.out.println(savingAccount); The output of the program should be: Account Number=879101 Balance=$8198.4 Interest Rate=0.04
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
