Results 1 to 4 of 4

Thread: Help!

  1. #1
    bamagirl31 is offline Member
    Join Date
    May 2011
    Posts
    47
    Rep Power
    0

    Default Help!

    I coded my project and I made two changes. I took those changes out and set the project back to the original form. It was running correctly before and displaying the different values in the loop. Now it only displays the same value which is the first value. Need help. This is frustrating. Thanks.

  2. #2
    bamagirl31 is offline Member
    Join Date
    May 2011
    Posts
    47
    Rep Power
    0

    Default

    package mortgage;

    /**
    *
    * @author Lekeisha
    **/
    public class Mortgage
    {
    public static void main(String[] args)
    {

    int amLoanOne = 200000;
    double monIntRate = 0.0;
    double monPay = 0;
    monIntRate = .0575/12;
    double totMons = 30*12;
    double intsPaid = 0;
    double princPaid = 0;
    double amLoanNxt = 0;


    monPay = amLoanOne*monIntRate/(1-(Math.pow((1+monIntRate), (-totMons))));
    //calculates the total payment amount for a year with interest rate of 5.75%
    for(int i = 0; i < 31; i++)
    {
    intsPaid+=i;
    princPaid+=i;
    amLoanNxt+=i;
    intsPaid = amLoanOne*monIntRate;
    princPaid = monPay - intsPaid;
    amLoanNxt = amLoanOne - princPaid;

    System.out.println("Interest for this year is $" + Math.round(intsPaid)+ ".");
    //calculates the total payment amount for 30 years with interest rate of 5.75%
    System.out.println("Mortgage payment amount is $" + Math.round(monPay)+ ".");
    System.out.println("Loan balance amount is $" + Math.round(amLoanNxt)+ ".");
    }
    }
    }

  3. #3
    Zack's Avatar
    Zack is offline Senior Member
    Join Date
    Jun 2010
    Location
    Destiny Islands
    Posts
    692
    Rep Power
    4

    Default

    At first glance, without running the code, I'm noticing something that could easily be the issue.

    On these three lines of code:
    Java Code:
    intsPaid = amLoanOne*monIntRate; 
    princPaid = monPay - intsPaid;
    amLoanNxt = amLoanOne - princPaid;
    ...you appear to overwrite the values of intsPaid, princPaid, and amLoanNxt with constant values from outside of the loop. My guess is that these three lines should be before the loop.

    PS: When posting code, please use CODE tags. ([code][/code])

  4. #4
    bamagirl31 is offline Member
    Join Date
    May 2011
    Posts
    47
    Rep Power
    0

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •