好吧,我还是Java的新手,我正在做这个东西的第九周。我将发布学校项目的一些源代码 - 这不是完整的源代码 - 这部分代码是我的循环来分期偿还贷款。我试图从菜单选择(菜单打印到文本字段)或用户输入中摊销。问题是,我无法弄清楚它是数学还是我的循环,它不是在正确地分期偿还贷款。我只想知道是否有人看到我错过的东西,如果有的话,请你指出来,以便我可以走上正确的轨道?提前致谢!使用Java swing组件循环分期偿还贷款。
来源:
private void amortizeButtonActionPerformed(java.awt.event.ActionEvent evt) {
// This module borrowed from Ryan Jones in George Griepp's PRG 420 class.
NumberFormat nf = NumberFormat.getCurrencyInstance();
int Monthly = 0;
int monthcount = 0;
String Output = "";
int i = 0; // For first loop
double loanamount = Double.parseDouble(tempTextField3.getText()); //all loan amounts are the same
double rate = Double.parseDouble(tempTextField1.getText()); //Array for the rate
double time = Double.parseDouble(tempTextField2.getText()); //Array for the time
double totalnumpayments = 0; //Set for
double monthlypayment = 0; //Set for math calculation in first loop
double interestPayment = 0; //Set for math calculation in first loop
double totaltime = 0; //Set for second loop to know how long to loop
double loan = 0; //Set for second loop
double interestPayment2 = 0; //Set for second loop
double principlePayment = 0; //Set for second loop
for (i = 0; i < time; i++) {//First loop This loops through the arrays and gives the first message listed below three times
monthlypayment = (loanamount * ((rate/12)/(1 - Math.pow((1 + (rate/12)), -(time * 12)))));
interestPayment = loanamount * (rate * 100/1200);
totaltime = (time * 12);
jTextArea1.setText("");
jTextArea1.setText("This loan has an interest rate of " + (rate * 100) + "%" + " and a starting loan amount of " + nf.format(loanamount));
jTextArea1.setText("Payment Number\t\t" + "Towards Principle\t\t" + "Towards Interest\t" + "Remaining on loan");
jTextArea1.setText(""); // Part of the first loop this will appear three times with the math listed above
System.out.println(totaltime);
Monthly++;
Output += ((monthcount++) + "\t\t\t" + nf.format(principlePayment) + "\t\t\t" + nf.format(interestPayment2) + "\t\t\t" + nf.format(loan - principlePayment) + "\n");
loan = -principlePayment;// Changes the numbers as the loop goes
interestPayment2 = loan * (rate * 100/1200);// Changes the numbers as the loop goes
principlePayment = monthlypayment - interestPayment2;// Changes the numbers as the loop goes
}
jTextArea1.setText(Output);
}
由于您正在学习,我认为这是使用调试器进行学习的适当时机。 – 2012-01-16 07:34:14
请学习java命名约定并坚持他们:-) – kleopatra 2012-01-16 07:42:41
顺便说一下,这是什么问题? (如:预期/预期与实际行为) – kleopatra 2012-01-16 07:44:38