A+ Finance Company guarantees a 2% monthly compounded return on your investment.
ID: 3804787 • Letter: A
Question
A+ Finance Company guarantees a 2% monthly compounded return on your investment. You want to see how long it takes to reach a total of $10,000,000 (10 million dollars) in investment plus return. Write a program that allows the user to enter a continuous monthly investment (Example - $500 every month) or ($1,000 every month). The Java program should call a recursive method ( a method that calls itself) that returns and displays the total months needed to reach the $10,000,000 goal. Example - At the 2% compounded monthly rate, and a $1,000 monthly investment, the first month should yield $1,020.00, the second month $2,060.40, the third month $3,121.61, the fourth month $4,204.04, etc. Display how many total months it takes the user to reach the million dollar goal. Remember, the user should be able to input the monthly continuing investment. The rate is always 2% and compounded monthly
Explanation / Answer
import java.util.Scanner;
public class CompoundInterest {
private int time=0;
private int totalAmount=10000000;
public int CalculateAmount(int rate,double amount) // Recursive Function
{
if(amount>=totalAmount)
return time;
else
{
amount*=rate;
time++;
return CalculateAmount(rate,amount);
}
}
public static void main( String args[] ) {
int months = 0 ;
double monthly_installment;
int rate = 2;
CompoundInterest obj = new CompoundInterest();
Scanner sc = new Scanner(System.in);
System.out.println("Enter Montly installment amount: ");
monthly_installment = sc.nextDouble(); // Reading the monthly_installment
months = obj.CalculateAmount(rate,monthly_installment);
System.out.println("Total months " + months );
}
}