Question: Write a class to keep track of a balance in a bank account with a varying annual interest rate. The constructor will set both the
Write a class to keep track of a balance in a bank account with a varying annual interest rate. The constructor will set both the baland theanacnenual interest rate to some initial values (and you should also implement a no-arguments constructor that sets both the balance and the interest rate to zero).
The class should have methods to change or retrieve the current balance or interest rate. There should also be methods to make a deposit (add to the balance) or a withdrawal (subtract from the balance).
Finally, there should be a method that adds interest to the balance at the current interest rate. This function should have a parameter indicating how many years’ worth of interest are to be added. (For example, 0.5 years indicates that the account should have six months’ interest added.)
Use the class as part of an interactive program that allows the user to determine how long an initial balance will take to grow to a given value. The program should allow the user to specify the initial balance, the interest rate, and whether there are additional yearly deposits.
Step by Step Solution
3.38 Rating (164 Votes )
There are 3 Steps involved in it
Here is an example of how you could implement a class to keep track of a bank account balance with a ... View full answer
Get step-by-step solutions from verified subject matter experts
