编写一个程序,计算投资值在给定利率以及给定年数下的未来值。计算公式如下:
未来值 = 投资总额 * ((1 + 月利率)^(年数 * 12))
月利率 = 年利率 / 1200
用TextField显示利率、投资总额、年数,当用户点击“计算”按钮时在文本域显示未来值。
代码如下:
Investment类:
package sample;
public class Investment {
private double totalInvestment;
private int year;
private double annualInterestRate;
public Investment(){
}
public Investment(double totalInvestment, int year, double annualInterestRate){
this.totalInvestment = totalInvestment;
this.year = year;
this.annualInterestRate = annualInterestRate;
}
public double getTotalInvestment(){
return totalInvestment;
}
public void setTotalInvestment(double totalInvestment){
this.totalInvestment = totalInvestment;
}
public int getYear(){
return year;
}
public void setYear(int year){
this.year = year;
}
public double getAnnualInterestRate(){
return annualInter