gpt4 book ai didi

java - 十年后学费上涨

转载 作者:行者123 更新时间:2023-11-29 04:37:39 26 4
gpt4 key购买 nike

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.

我可以很容易地计算出第十年的学费。让我感到困惑的是如何在 11、12、13 和 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);

最后一个 while 循环是我尝试添加 4 年。我如何在第 11 到 14 次迭代中提取 TotalCost 的唯一值并添加它们?

最佳答案

因为你想每年增加 5%,而不是 rate = 5

您应该有 rate = 1.05

使用 1.05 的速率你可以做到这一点

FeeAtYear1 = 10000*1.05^0 = 10000

FeeAtYear2 = 10000*1.05^1 = 10500

FeeAtYear3 = 10000*1.05^2 = 11025

FeeAtYear4 = 10000*1.05^3 = 11576.25

...

FeeAtYear10 = 10000*1.05^9 = ~16288.95

你甚至不需要 while 循环。

TotalCost = 10000 *1.05^10 + 10000 *1.05^11 + 10000 *1.05^12 + 10000 *1.05^13;

关于java - 十年后学费上涨,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40590379/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com