This is what i have so far.. i've figured out how to do the mortgage payment but I am having trouble displaying the loan balance and interest paid for each payment over the term of the loan. can someone please help with the code and formulas?
Here's the code i have thus far.
/*Heather Davison
*/
package mortgagecalc;
/* A program written in Java that will calculate and display the monthly payment amount to a $200,000.00 loan over a 30 year term at a 5.75‰ interest rate. */
import java.lang.Math.*;
/* Program uses the Math class to perform mathematical functions. */
public class Main //Beginning
{
public static void main(String[] args) //tells the program what to do
{
/* P = principal, the initial amount of the loan
I = the annual interest rate (from 1 to 100 percent)
L = length, the length (in years) of the loan, or at least the length over which the loan is amortized.
J = monthly interest in decimal form = I / (12 x 100)
N = number of months over which loan is amortized = L x 12
M = the monthly payment
M = P * ( J / (1 - (1 + J) ** -N))
Above are the definitions and terms to create an equation to calculate the mortgage payment.
http://www.hughchou.org/calc/formula.html
*/
double dblmonthlypayment; // payment
double dblprincipal=200000; // Amount of principal
int intyears=30; // Number of years in loan
int intnumberOfMonthsAmortize; // Number of Months
double dblinterest=5.75; // Interest Rate
double dblmonthlyInterest; // Monthly Interest Rate
dblmonthlyInterest = dblinterest/(12*100); //J monthly interest
intnumberOfMonthsAmortize = intyears*12; //N number of months
dblmonthlypayment = dblprincipal*(dblmonthlyInterest / (1 - Math.pow((1 + dblmonthlyInterest), -intnumberOfMonthsAmortize))); // Forumla M = P * ( J / (1 - (1 + J) ** -N))
System.out.println(); //spacing
System.out.println("Principal of the loan = $200,000");// displays as is
System.out.println("Loan length = 30 years"); // displays as is
System.out.println("Loan Interest = 5.75%"); // displays as is
System.out.println("Monthly payment = $ " +dblmonthlypayment); // displays as is and monthly payment result based on the calculation
System.out.println(); // spacing
}
}