//The java.io package provides for system input and output through data streams import java.io.*; //A subclass of the NumberFormat used to format numbers in Java programs import java.text.DecimalFormat; public class AmandaMortgageRate { //The main function for the mortgage calculator public static void main(String[] args) throws IOException { //Declaring and constructing variables int [] iTerm = {84, 180, 360}; double [] dInterest = {5.35, 5.5, 5.75}; double dPayment, dRate, dAmount = 200000, dMonthlyInterest,dMonthlyPrincipal, dMonthlyBalance; DecimalFormat twoDigits = new DecimalFormat("$#,000.00"); //to format monthly payment. DecimalFormat df = new DecimalFormat("###,##0.00"); // to format the amount. DecimalFormat numDf = new DecimalFormat("000"); // to format the sequence number. //output for month to years System.out.println(); System.out.println("Welcome to Amanda's Mortgage Calculator"); System.out.println(); //Loop for the varying Mortgage Rates and Payments int p; for (p = 0; p <= 2; p ++) { //Calculation for the monthly mortgage payment //Calculations Retrieved from [url="http://www.1728.com/loanform.htm"]http://www.1728.com/loanform.htm[/url] on 8/15/08 dRate = dInterest[p] / 1200; dPayment = (dAmount * dRate) / (1 - Math.pow(1 / (1 + dRate), iTerm[p])); dMonthlyInterest = (dAmount / 12) * (dInterest[p] / 100); dMonthlyPrincipal = (dPayment - dMonthlyInterest); dMonthlyBalance = (dAmount - dMonthlyPrincipal); int totalNumberOfMonths; int monthCounter=1; // Output for the loan information and the monthly payment int nbYear = iTerm[p] / 12; System.out.println(); System.out.println("Your Monthly Payment for a " + nbYear +" years loan of $200,000 at " + dInterest[p]+ "% is:" + twoDigits.format (dPayment)); System.out.println(); for(; totalNumOfMonths>0; totalNumOfMonths--) { //Output for loan information, monthly payment, and amortization schedule of payments System.out.println("Payment# LoanBalance InterestPaid"); System.out.println(numDf.format(monthCounter) + " " +df.format(dMonthlyPrincipal)+ " " +df.format(dPayment-dMonthlyPrincipal))); System.out.println("\n"); monthCounter++; if(monthCounter%25==0)sleep(1000); // this will hesitate... } } } //function for the calculation of the interest into the loan payment public double MonthlyInterest() { //Declaring Variables for interest on the loan double dMonthlyInterest = 0.0; double dAmount = 0.0; double dInterest = 0.0; //Calculation for monthly interest dMonthlyInterest = (dAmount / 12) * (dInterest / 100); return dMonthlyInterest; } //function for the calculation of the interest into the loan payment public double monthlyInterest() { //Declaring Variables for interest on the loan double dMonthlyInterest = 0.0; double dAmount = 0.0; double dInterest = 0.0; //Calculation for monthly interest dMonthlyInterest = (dAmount / 12) * (dInterest / 100); return dMonthlyInterest; } //function of the calculation of the monthly principal for the loan payment public static double monthlyPrincipal() { //Declaring Variables for monthly principal double dMonthlyPrincipal = 0.0; double dPayment = 0.0; double dMonthlyInterest = 0.0; //Calculations for monthly principal dMonthlyPrincipal = (dPayment - dMonthlyInterest); return dMonthlyPrincipal; } //function for the calculation of the monthy loan balance public static double monthlyBalance() { //Declaring Variables for monthly loan balance double dMonthlyBalance = 0.0; double dAmount = 0.0; double dMonthlyPrincipal = 0.0; //Calculations for monthly loan balance dMonthlyBalance = (dAmount - dMonthlyPrincipal); return dMonthlyBalance; } // method to make the program sleep (hesitate) for a given time (in seconds).. public static void sleep(long milliseconds) { try{ Thread.sleep(milliseconds); } catch(InterruptedException e) { //do nothing... for now... } } }

*edit: Please use code tags in the future, thanks!

This post has been edited by **Martyr2**: 12 May 2008 - 04:25 PM