第五章第七题(金融应用:计算将来的学费)(Financial application: compute future tuition)
发布时间
阅读量:
阅读量
5.7(金融应用:计算将来的学费)
设某大学今年的学费为1万美元(即1\text{万}美金}),其年增长率为5%。第一年后预计为1.05万美元(即1.05\text{万}美金}$)。请开发一个程序来计算该大学在第十年后的学费金额,并从当前年开始计算后续四年内(即接下来四年内)的总学费费用总额是多少?
5.7(Financial application: compute future tuition) Assume that a university's tuition for this academic year is 10,000 and increases by 5% each subsequent year. In the following academic year, the tuition will amount to 10,500. Develop a program to calculate the tuition fee for ten years ahead and determine the cumulative cost over four academic years starting from the eleventh.
下面是参考答案代码:
public class ComputeFutureTuitionQuestion7 {
public static void main(String[] args) {
double tenYearsTuition = 10000,fourYearsTotalTuition = 0;
for(int year = 1;year <= 10;year++)
tenYearsTuition *= 1.05;
System.out.println("The tuition in ten years is " + tenYearsTuition);
for(int year = 1;year <= 4;year++)
{
tenYearsTuition *= 1.05;
fourYearsTotalTuition += tenYearsTuition;
}
System.out.println("The total cost of four years’ worth of tuition after the tenth year "
+ fourYearsTotalTuition);
}
}
运行效果:

注意:编程时需培养良好的习惯
1.文件名称必须使用英文且尽量具体明确
2.注释内容也应遵循英文书写规范
3.变量命名需具有明确性避免使用a b c等简略符号同时建议采用驼峰式命名法
4.在整体风格上应保持一致性:
- 避免在同一位置混合运用不同的区分策略例如有些地方用下划线分隔词组而另一些地方则采用其他方法
- 同一逻辑模块之间应统一设置行距间距以确保可读性和一致性
5.遵循以下命名规范: - 对于普通变量及其方法名称应当采用小驼峰式命名法
- 类别名称则应遵循大驼峰式命名规则
- 常量名称建议全部大写字母并附加下划线以增强可识别性
6 学习编程工具时可以参考像Visual Studio这样的编辑器了解其常用快捷键操作方式例如Ctrl+Shift+B可快速实现对齐功能以提高工作效率
全部评论 (0)
还没有任何评论哟~
