Suponga que la matrícula de una universidad es de $ 10,000 este año y aumenta un 5% cada año.

IDIOMA: Java

DESAFÍO:

Suponga que la matrícula de una universidad es de $ 10,000 este año y aumenta un 5% cada año. En un año, la matrícula será de $ 10,500. Escriba un programa que muestre la matrícula en 10 años y el costo total de la matrícula de 4 años a partir del décimo año.

SOLUTION:

public class Exercise_1 {
    public static void main(String[] args) {
        int totalCost = 0;		// Accumulate total cost of four years tuition
        int tuition = 10000;
        int tuitionTenthYear;
    
        for (int year = 1; year <= 14; year++) {
            // Increase tuition by 5% every year
            tuition += (tuition * 0.05);  
    
            if (year > 10) // Test for after 10 years
                totalCost += tuition; // Accumulate tuition cost
    
            // Cost of tution in ten years
            if (year == 10)
                tuitionTenthYear = tuition; 
        }
    
        // Display the cost of tuition in ten years
        System.out.println("Tuition in ten years: $" + tuitionTenthYear);
    
        // Display the cost of four years' worth of tuition after tenth year
        System.out.println("Total cost for four years' worth of tuition" +
            " after the tenth year: $" + totalCost);
    }
}