English 中文(简体)
利用 Java周转部件摊还贷款。
原标题:Amortizing a loan using a loop with Java swing components .

奥凯,我仍然对贾瓦有新鲜事,我正走到这一 st的第九周。 我将从一个学校项目上张贴一些来源代码——这是整个来源的NOT——这部法律是我摊还贷款的空档。 我试图从菜单选择(向文字领域打印)或用户投入中摊销。 问题在于,如果是数学,还是我的住所,那么我就不能说贷款没有适当摊销。 我只想知道,任何人是否看到我所忽略的一点显而易见,如果是,请指出这一点,我就可以走上正确的轨道? 提前感谢!

来源:

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		" + "Towards Principle		" + "Towards Interest	" + "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++ ) + "			" + nf.format( principlePayment ) + "			" + nf.format( interestPayment2 ) + "			" + nf.format( loan - principlePayment ) + "
" );


    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 );
}
最佳回答

有几个问题,可能不是(我不熟悉loans

  1. You calculated totaltime in your for-loop, without making use of the i variable. Hence it will always result in the same result, and can be calculated outside the loop
  2. By calling setText on the jTextArea1 inside the loop, where your last call is with the empty String, you might as well clear it before entering the for-loop, as in the end the jTextArea1 will just be empty. Or just remove the code since after the for loop you set the text to Output
  3. The loan = -principlePayment is a weird statement. So if the principlePayment is a positive number, loan will be a negative number, and interestPayment2 as well
  4. You would better use a StringBuilder to construct your Output variable

I think number 3 is the most important for your calculations.

问题回答

暂无回答




相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...

热门标签