Java Compound Interest

Your Task:

Create a method that takes principal and rate and time as inputs and outputs the new principal with interest.

Call your compound interest method from the main method with different inputs and print the results to the console.

Requirements:

  • Your compound interest method must be a separate method from the main method, and the main method must call your other method.
  • Your compound interest method must have three input parameters and it must use a return statement to output the new principal.
  • You must use a for loop to calculate the interest repeatedly. Hint: you can use a variable (parameters are variables) in the for loop.

Compound Interest Calculations

Here’s how it works:

principle = the amount of money you start with

rate = percentage interest rate per time period
(this should be in decimal form, so use 0.05, not 5%)

time is actually the number of time periods to calculate interest over; this can be years, months, or whatever you like.

If you compound yearly, you can use your annual interest rate as is. If you compound monthly, you need to divide your interest rate by 12. If you compound daily, you need to divide the interest rate by the number of days in a year.

Calculating Interest for one time period:

Multiply the interest rate (as a decimal) by the principle. This is the interest earned. Now add the interest to the principal. This is the new principle.

To calculate compound interest, you repeat this process as many times as necessary. The new principle becomes the principle for the next interest calculation each time.