Homework Assignment Three: Interests

In this assignment you will be practicing with while and for loops.

First, write an algorithm to settle the following question:

A bank account starts out with $10,000. Interest is compounded at the end of every month at 6 percent per year (0.5 percent per month). At the beginning of every month, $500 is withdrawn to meet college expenses after the interest has been credited. After how many years is the account depleted?
This problem is listed as Exercise R1.16 (page 44) in your text.

Now suppose the numbers ($10,000, 6 percent, $500) were user-selectable. Are there values for which the algorithm you developed would not terminate? If so, make sure it always terminates.
This extension is listed as Exercise R1.17 (page 44). This will be your assignment.

Therefore you are two write a program that asks the user for three values:

Then if the program can determine that the account will eventually be depleted, it will report in how many years this will happen, otherwise, if the program determines that for the values provided by the user the account will never get depleted, the program will report that and end. Here's a sample session with your program:
frilled.cs.indiana.edu%java Interests
Welcome to the financial calculator.
What's your initial balance? 10000
What's the yearly interest? 6
How much do you plan to withdraw monthly? 500
The account will last 1 year(s) and 9 month(s).
Ending balance will be: 62.2 dollars.
frilled.cs.indiana.edu%java Interests
Welcome to the financial calculator.
What's your initial balance? 10000
What's the yearly interest? 6
How much do you plan to withdraw monthly? 100
The account will last 11 year(s) and 6 month(s).
Ending balance will be: 97.09 dollars.
frilled.cs.indiana.edu%java Interests
Welcome to the financial calculator.
What's your initial balance? 10000
What's the yearly interest? 6
How much do you plan to withdraw monthly? 10
This will last forever.
frilled.cs.indiana.edu%java Interests
Welcome to the financial calculator.
What's your initial balance? 10000
What's the yearly interest? 6
How much do you plan to withdraw monthly? 50
The account will last 525 year(s) and 1 month(s).
Ending balance will be: 48.1 dollars.
frilled.cs.indiana.edu%

Please call your program (the class) Interests for faster grading.


Last updated: Jul 5, 2001 by Adrian German for A201