Question
Complete the constructor of the SavingsAccount class that is a subclass of the BankAccount class. Complete the following file: /** An account that earns interest
Complete the constructor of the SavingsAccount class that is a subclass of the BankAccount class.
Complete the following file:
/** An account that earns interest at a fixed rate. */ public class SavingsAccount extends BankAccount { private double interestRate;
/** Constructs a bank account with a given interest rate. @balance initialBalance the initial balance @param rate the interest rate */ public SavingsAccount(double initialBalance, double rate) {
// your work here
}
/** Adds the earned interest to the account balance. */ public void addInterest() { double interest = getBalance() * interestRate / 100; deposit(interest); }
// This method checks your work. Do not modify it. public static double check(double initialBalance, double rate) { SavingsAccount account = new SavingsAccount(initialBalance, rate); account.addInterest(); return account.getBalance(); } }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started