The first program
Before we can learn how to compile and execute Java code, we need a Java program to work with. Our first program will calculate compound interest. There is a quote attributed to Albert Einstein, who is said to have stated, “Compound interest is the eighth wonder of the world.” Whether he ever said this remains in doubt. Regardless, calculating interest on interest is one of the most important financial calculations that can be performed. Here is the formula that we will implement:
Here, P is the principal amount deposited into a compound interest account, r is the interest rate typically expressed as an annual rate, n is the number of compounding periods (if compounded monthly, then the value is 12), and t is the time the money will compound for. This is expressed in years and must be divided by the number of compounding periods, which, in this case, will also be 12.
In Part 2 of this book, we will examine the syntax and...