Math model for Bank Savings using programming

44 Views Asked by At
 Starting conditions:
    -------------------
       Age: 327 months (27 years, 3 months)
       Savings: $21,345

Write a function which computes earned sum after each month

Working:
 --------
  Months: 489
  Per Month Savings: $1000
  Rate of Return:  4.5% per year ( 0.045/12 per month) 
                   [above inflation]

I need to find out how many dollars after 489 months knowing that now I am 327 months old and my current savings are $21345.

I managed to solve this problem using geometric progression, and of course using powers. But now, I would like to compute without using powers. I would like to use a function, like in programming. Do you have any idea?

Thanks!

1

There are 1 best solutions below

0
On
public static void main(String[] args)
{
    double currentSavings= 21345,currentAge= 327,futureAge  = 489,
    periodicPayment = 1000;
    double annumInterest = (4.5/100);

    double monthlyInt = annumInterest/12;
    double total = currentSavings;
    for(double i = currentAge; i<futureAge; i++)
    {
        total *= (1+monthlyInt);
        total += periodicPayment;
    }

    //if you want to add rounding:

    total *= 100;
    total = Math.round(total);
    total /= 100;
    System.out.println(" $ "+ total);
}

Output: $ 261475.11