Introductory Programming In Java
| HW 1 |
HW 2 |
HW 3 |
HW 4 |
HW 5 |
HW 6 |
HW 7 |
Homework 1
Growing money with loops
The problem
A simple example of a question that you might ask of a computer is
How many years does it take to accumulate $20,000 in a bank account
if you start with $10,000 and interest is fixed at 5% compounding
annually?
Code up and run a program to solve this problem.
HINT: Draw up a table of your bank balance after 1 year, 2 years and so on:
Year Balance ($) 0 10,000 1 10,000 + 0.05*(10,000) 2 Year 1 balance + 0.05*(Year 1 balance) 3 Year 2 balance + 0.05*(Year 2 balance) ... ... ...
You could write a program to print this output and then run it for, say, 10 years. You could then decide how you might write a program which will find out how many years you would need to accumulate $20,000.
Note that you will need to use a loop to write this program. Because we may not have yet covered this in lectures, you may wish to wait a little, or learn it on your own (in the text book, or in the lecture slides, or in Java Tutorial).
Assessment
You will get up to two marks, if you present a solution to the Homework exercise during the next week lab.
| HW 1 |
HW 2 |
HW 3 |
HW 4 |
HW 5 |
HW 6 |
HW 7 |
