qwertyuiop - 1 year ago 167
Java Question

# Rising tuition cost after ten years

Suppose that the tuition for a university is \$10,000 this year and increases 5% every year. In one year, the tuition will be \$10,500. Write a program that computes the tuition in ten years and the total cost of four years' worth of tuition after the tenth year.

I can calculate the tenth year tuition easily enough. What has me stumped is how to add the unique tuition values at years 11, 12, 13 and 14.

``````double Fee = 10000;
double Year = 1;
double TotalFee;
double Rate = 5;
double TotalCost = 15000 + 15500 + 16000 + 16500;

System.out.println("Year   "  + " Total Fee  ");
System.out.println();

while (Year <= 14) {
TotalFee = Fee + ((Fee * ((Year * Rate) - Rate)) / 100);
System.out.println(Year + "  " + "       "+ TotalFee);`
Year++;
}

System.out.println("Total cost tuition of 4 years starting 10 years from now is " + TotalCost);
``````

The last while loop is my attempt at adding the 4 years. How could I pull out the unique values of TotalCost at iterations 11 to 14 and add them?

Since you want to increase the amount 5% every year, instead of having `rate = 5`

you should do `rate = 1.05`

With the rate as 1.05 you can do this

Fee at Year 1 = 10000*1.05^0 = 10000

Fee at Year 2 = 10000*1.05^1 = 10500

Fee at Year 3 = 10000*1.05^2 = 11025

Fee at Year 4 = 10000*1.05^3 = 11576.25

...

Fee at Year 10 = 10000*1.05^9 = ~16288.95

You don't even need a while loop :)

``````TotalCost = 10000 *1.05^10 + 10000 *1.05^11 + 10000 *1.05^12 + 10000 *1.05^13;
``````
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download