← all problems

compoundInterest 🌶️🌶️

Write a method that takes a double parameter principal (a starting amount of money), a double parameter rate (an interest rate, like 0.1 for 10%), and an int parameter years, and returns the total value after compounding that interest once a year for that many years, using the formula principal (1 + rate)^years. For example, compoundInterest(1000, 0.1, 2) should return 1210.0, since 1000 (1.1)^2 is 1210. Use Math.pow from the Math class.