What equation do I have to put here to have an accurate increase of 4.7% every year?

54 Views Asked by At

I'm dragging this question over from another website from a recommendation.

I'm writing a program in BlueJ that gets the starting price of Tuition in the first year ($8000) and for each year afterwards the price raises by 4.7%.

public class Tuition
{
    public static void main(String[] args)
    {
        int years;  
        final double Tuition = 8000;
        double Price;
        years = 1;
        System.out.printf("%15s %15s\n", "Year", "Tuition Price");
        while (years <= 4)
        {
            Price = years + 8000;
            System.out.printf("%15d %15.1f\n", years, Price);
            years ++;
        }
    }
}

Now obviously the only line (I think) I need help with is

 Price = years + 8000;

Because right now with the way I have it it just adds 8000 to every year. (8001 for year one, 8002 for year two, etc.)

What's the equation I would write in that line to get the yearly 4.7% increase? Thanks.

2

There are 2 best solutions below

3
On

How about

Price = 8000 * ((1+ 0.047)^years);

Edit: if you want to avoid "^", initiate before the loop with

Price = 8000;

then, inside the loop, replace

Price = years + 8000;

with

Price = Price * 1.047;

The rest of the code stays unchanged.

0
On

Remember the formula for compound interest.

So your line should be:

Price = 8000 * (1.047^years)

I don't know Java, so I don't know if ^ is the right operator here. But you want to raise 1.047 to the power of the number of years.