/*Week 2 Assignment Individual Assignment Service Request SR-mf-003 Heather Davison POS420 */ 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. */ import java.text.NumberFormat; // formats the number as currency, with a decimal place and $ 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 NumberFormat nf = NumberFormat.getCurrencyInstance(); // formats the number as currency, with a decimal place and $ dblmonthlyInterest = dblinterest/(12*100); //J monthly interest intnumberOfMonthsAmortize = intyears*12; //N number of months //Declares formula dblmonthlypayment = dblprincipal*(dblmonthlyInterest / (1 - Math.pow((1 + dblmonthlyInterest), -intnumberOfMonthsAmortize))); System.out.println(); //Spacing System.out.println("Mortgage Calculator"); //Display as is System.out.println("Principal of the loan = $200,000"); //Display as is System.out.println("Loan length = 30 years"); //Display as is System.out.println("Loan Interest = 5.75%"); //Display as is System.out.println("Your monthly payment is: " + nf.format(dblmonthlypayment)); //Display as is System.out.println(); //Spacing //Declares and builds three new variables double loanBalance = 0; double interestPaid = 0; int lineCount = 20; int x=0; loanBalance = dblprincipal - dblmonthlypayment; interestPaid = loanBalance * dblmonthlyInterest; //Starts loop statement,and declares formula for loan balance and interest paid while (loanBalance > 0) { //Displays the loan balance and interest paid System.out.println("The loan balance is: " + nf.format(loanBalance)); System.out.println("The interest paid on the loan is: " + nf.format(interestPaid)); loanBalance = loanBalance - dblmonthlypayment; interestPaid = loanBalance * dblmonthlyInterest; /* This is the original calculation that I normally use to calculate payment * It generates a different payment than the one used in class but calculating the * correct payment in not the general idea here. * pay = cost * ((tax/(12*100))/(1-Math.pow(((tax/(12*100))+ 1),(-1*mins)))); */ dblmonthlyInterest = dblinterest/(12*100); dblmonthlypayment = dblprincipal * (dblmonthlyInterest/(1-Math.pow((dblmonthlyInterest + 1),(-intyears)))); for (x=1;x<=intyears;x++) { if (x % 6 == 0) { System.out.println("Press any key to continue"); try { System.in.read(); } catch (Exception e) {;} } System.out.println("Schedule\t" + x + "\t" + intnumberOfMonthsAmortize + "\t" + nf.format (dblprincipal) + "\t" + nf.format(loanBalance)); } } } }

*Results from run* is this how it's supposed to look????

Mortgage Calculator

Principal of the loan = $200,000

Loan length = 30 years

Loan Interest = 5.75%

Your monthly payment is: $1,167.15

The loan balance is: $198,832.85

The interest paid on the loan is: $952.74

Schedule 1 360 $200,000.00 $197,665.71

Schedule 2 360 $200,000.00 $197,665.71

Schedule 3 360 $200,000.00 $197,665.71

Schedule 4 360 $200,000.00 $197,665.71

Schedule 5 360 $200,000.00 $197,665.71

Press any key to continue

Schedule 6 360 $200,000.00 $197,665.71

Schedule 7 360 $200,000.00 $197,665.71

Schedule 8 360 $200,000.00 $197,665.71

Schedule 9 360 $200,000.00 $197,665.71

Schedule 10 360 $200,000.00 $197,665.71

Schedule 11 360 $200,000.00 $197,665.71

Press any key to continue

Schedule 12 360 $200,000.00 $197,665.71

Schedule 13 360 $200,000.00 $197,665.71

Schedule 14 360 $200,000.00 $197,665.71

Schedule 15 360 $200,000.00 $197,665.71

Schedule 16 360 $200,000.00 $197,665.71

Schedule 17 360 $200,000.00 $197,665.71

Press any key to continue

Schedule 18 360 $200,000.00 $197,665.71

Schedule 19 360 $200,000.00 $197,665.71

Schedule 20 360 $200,000.00 $197,665.71

Schedule 21 360 $200,000.00 $197,665.71

Schedule 22 360 $200,000.00 $197,665.71

Schedule 23 360 $200,000.00 $197,665.71

Press any key to continue

Schedule 24 360 $200,000.00 $197,665.71

Schedule 25 360 $200,000.00 $197,665.71

Schedule 26 360 $200,000.00 $197,665.71

Schedule 27 360 $200,000.00 $197,665.71

Schedule 28 360 $200,000.00 $197,665.71

Schedule 29 360 $200,000.00 $197,665.71

Press any key to continue

Schedule 30 360 $200,000.00 $197,665.71

The loan balance is: $197,665.71

The interest paid on the loan is: $947.15

Schedule 1 360 $200,000.00 $190,492.47

Schedule 2 360 $200,000.00 $190,492.47

Schedule 3 360 $200,000.00 $190,492.47

Schedule 4 360 $200,000.00 $190,492.47

Schedule 5 360 $200,000.00 $190,492.47

Press any key to continue

Schedule 6 360 $200,000.00 $190,492.47

Schedule 7 360 $200,000.00 $190,492.47

Schedule 8 360 $200,000.00 $190,492.47

Schedule 9 360 $200,000.00 $190,492.47

Schedule 10 360 $200,000.00 $190,492.47

Schedule 11 360 $200,000.00 $190,492.47

Press any key to continue

MOD EDIT: When posting code...USE CODE TAGS!!!

Also, please use DESCRIPTIVE titles when posting topics. You posted this topic in the Java Forum, therefore we KNOW you need JAVA Help!

This post has been edited by **JackOfAllTrades**: 03 October 2010 - 02:56 PM

Reason for edit:: Added code tags and added descriptive title.