Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7069581
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T05:27:46+00:00 2026-05-28T05:27:46+00:00

Okay, I am still new to Java, and I am going on my ninth

  • 0

Okay, I am still new to Java, and I am going on my ninth week of this stuff. I am going to post some source code from a school project – this is NOT the entire source – this chunk of code is my loop to amortize a loan. I am trying to amortize from a menu selection (menu prints to a text field) or from user input. The problem is, and I cannot figure out if it is math, or my loop, is that it is not amortizing the loan properly. I just want to know if anyone sees something obvious that I missed, and if so could you please point it out so I can get on the right track? Thanks in advance!

SOURCE:

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 );
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T05:27:47+00:00Added an answer on May 28, 2026 at 5:27 am

    There are a few things, which might be an issue or not (I am not familiar with the maths behind 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.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am still new to this Memory Management stuff (Garbage Collector took care of
Okay well I apologize for how sloppy this code is, but I still cant
Edit: Okay, this code still doesn't allow me to use two different textures in
I am new to WiX but I have done some stuff with Installshield and
Okay, I'm still new to the whole ASP.NET and exactly how it posts back
Okay so here's the lowdown... been working on this solution for the past week
Okay still having a few problems with it, this is what I have so
Okay I;m really new to VB.NET and desktop application development. Simplified this is what
(I'm not sure if that title is worded correctly, as I'm still new to
I heard that .NET 4 has a new caching API. Okay, so the good

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.