1. public static double investmentValue(double amount, double interest, int numY
ID: 3702259 • Letter: 1
Question
1. public static double investmentValue(double amount, double interest, int numYears)
Write a recursive method that takes as parameters an initial investment amount, an annual interest rate, and a number of years. The method should return the value of the investment after the given number of years, assuming that the interest is compounded annually. (For example, if the initial investment is 1000 and the interest rate is 10 percent, then after one year the investment will be worth 1100, after two years 1210, after three years 1331, etc)
Explanation / Answer
public static double investmentValue(double amount,double interest,int numYears)
{
if(numYears>0)
{
amount = amount* (100+interest)/100;
numYears--;
return investmentValue(amount,interest,numYears);
}
else
{
return amount;
}
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.