Home » Amortization Calculator

JAVA programming code writing question?

Written By: aaren on December 23, 2009 One Comment

Ok , I am doing an assignment for a mortgage calculator in JAVA. The assignment is to write the code first, then enter into JAVA to do. I am all new to this so……Here is my code and it will not do. I am lost as lost can be. Any help will be appreciated.

public class MortageCalculator {
public static void main(String [] args) {

//declare variables
double interestRate=.0575;
int amount=200000;
int term=30;
double monthlyInterestRate=interestRate / 12;
int totalMonths=term * 12;
double payment=amount * (1-(Math.pow((1+monthlyInterestRate ),(-totalMonths))));

//show payment amount
System.out.println("The monthly payment for your mortage is" + payment);
}
}

Here is the info:

Formula for mortgage payment calculation:

a = [P(1 + r)nr]/[(1 + r)n - 1] — where P is the principal amount, r is the interest rate and n is the term in years.

Formulas to calculate the monthly payment and balance:

interestRate = .0575;
amount = 200000;
term = 30;
monthlyInterestRate = interestRate / 12;
totalMonths= term * 12;
payment = amount * monthlyInterestRate / (1-(Math.pow((1+monthlyInterestRate ),(-totalMonths))));

Formulas to calculate the amortization:

interestPaid = loanBalance * montlyInterestRate;
principalPaid = payment – interestPaid;
loanBalance = loanBalance – principalPaid;
//loanBalance is a running number, the initial value is equal to amount
I wrote this in notepad.

Related Posts

Tags: , , , , , , , , , , , , ,

Digg this!Add to del.icio.us!Stumble this!Add to Techorati!Share on Facebook!Seed Newsvine!Reddit!Add to Yahoo!

Top incoming search terms for this post

One Response to “JAVA programming code writing question?”

  1. crappyT on: 23 December 2009 at 4:36 am

    I tried to do your code and it works fine (I’m not sure about the formula and all but wrt programming, it’s fine).
    Just as a check:
    name the file as MortageCalculator.java
    build as : javac MortageCalculator.java
    do as : java MortageCalculator

    For ease in debugging, you can use a excellent IDE such as Eclipse. or at least notepad++

  Copyright ©2009 Loan Tags, All rights reserved.| Powered by WordPress| Gandhi theme by Techblissonline.com