Ads

Hi this is my first java class, and i have been trying for hours to do this program. it is a recursion problem where the user will enter a continuous monthly investment, at a rate of 1% the program should say how many months will it take to reach a million dollars plus return. any help would be appreciate it because i cant see what im doing wrong.

public class FinServiceCo { public static void main(String[] args) { StdOut.println("We are eager to help you reach your financial goals, that is why our company guarantees you a 1% monthly compounded return on your investments"); StdOut.println("How much money will you like to invest today?"); double money= StdIn.readDouble();//amount of money invested monthly double sum = Sum(money);//total amount of money after certain number of months double month = Month(money,sum);//calculates number of month for sum to reach 1 million dollar StdOut.printf("after %.2f months",month);//prints out number of months StdOut.print("you have reached an amount of"); StdOut.printf("%.2f",sum);//print out the sum of money StdOut.println(); } public static double Sum( double money) { money = (money*0.01)+money;//increase the sum by 1 percent if(money>=1000000)//if the sum is over million dollars then returns it to function call return money; else//else repeat function { money=money+money;//increse a sum by amount invested monthly return money;//return sum } } public static double Month( double money, double month)//function to calculate number of months to reach 1 million dollars { money = money*1.01;//increase sum by 1 percent month=month+1;//increse a month by one if(money>=1000000)//if statement if sum is more than 1 million dollar return number of months return month; else//else repeat function { money=money+money;//increse sum by money invested monthly month=Month( money, month);//repeat function } return month; } }

Ads

View Answers

Ads

Related Tutorials/Questions & Answers: