好吧,我還是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