Suppose that the tuition for a university is $10,000 this year and increases 5% every year. In this java lesson, write a program that computes the tuition in ten years and the total cost of four years’ worth of tuition starting ten years from now.
public static void main(String[] args) { int tuitionPerYear = 10000; int totalCost = 0; for (int i = 1; i <= 14; i++) { tuitionPerYear += tuitionPerYear * .05; if (i == 10) { System.out.println("The cost of tuition in 10 years is $" + tuitionPerYear); } if (i > 10) { totalCost = totalCost + tuitionPerYear; } } System.out.println("The total cost of 4 years tuition in 10 years is $" + totalCost); }
The cost of tuition in 10 years is $16284 The total cost of 4 years tuition in 10 years is $73690