gpt4 book ai didi

java - 贷款复利计算器java

转载 作者:行者123 更新时间:2023-12-02 05:48:24 26 4
gpt4 key购买 nike

double a = Double.parseDouble(amount.getText());
double r = Double.parseDouble(rate.getText())/100;
double y = Double.parseDouble(years.getText());
double m=y*12;
double simple =a+(a*r*y);
double compound = a * Math.pow(1+ r, m);
String d = String.format("%.2f", simple);
String d1 = String.format("%.2f", simple/12);
String d2 = String.format("%.2f", compound);
int x=1;

while(x<=m && type.getSelectedItem().equals("Simple")) {
monthly1.append(String.valueOf(x+(". ")+d1+("\n")));
x++;
total1.setText(String.valueOf(d));
}

if (type.getSelectedItem().equals("Compound")){
for (int month=1;month<=m;month++){
monthly2.append(String.valueOf(month+(". ")+d2+"\n"));
total2.setText(String.valueOf(d2));
}
}

单利可以,但月复利不行。我试过了

amount:1000 rate:5 years 3.

得到了

1. 5791.82
2. 5791.82
3. 5791.82

up to 60.

我希望它显示我每月必须支付的费用。

最佳答案

您似乎只在代码的最开始计算compound一次。我将创建一个方法calculateCompoundInterest(int Month),然后从循环中调用它,如下所示:

for (int month=1; month <= m; month++) {
String monthlyAmount = String.format("%.2f", calculateCompoundInterest(month));
monthly2.append(String.valueOf(month+(". ")+monthlyAmount+"\n"));
total2.setText(String.valueOf(d2));
}

关于java - 贷款复利计算器java,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23823304/

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