import java.io.*; public class MortgagePayment3 { public static void main(String[] args) throws IOException { String principal,annualInterest,years; //*Principle amount of loan int annRate; BufferedReader dataIn= new BufferedReader(new InputStreamReader(System.in)); System.out.println("Enter Principal Amount "); principal = dataIn.readLine(); System.out.println("Enter term of the loan, ex. 30 years "); years = dataIn.readLine(); System.out.println("\nEnter your interest rate"); //*Interest rate of loan annualInterest = dataIn.readLine(); annRate = Integer.parseInt(annualInterest); System.out.println("\nThe Following is your output based on the amount: \n"); //*Will show output in the following format } public static double calculatePayment(double principal, double annRate, int years){ double monthlyInt = annRate / 12; double monthlyPayment = (principal * monthlyInt) / (1 - Math.pow(1/ (1 + monthlyInt), years * 12)); //*Shows 1 monthly payment multiplied by 12 to make one complete year. return format(monthlyPayment, 2); } public static double format(double amount, int mortgage) { double temp = amount; temp = temp * Math.pow(10, mortgage); temp = Math.round(temp); temp = temp/Math.pow(10, mortgage); return temp; } public static void print(double pr, double annRate, int years){ double mpayment = calculatePayment(pr, annRate, years); System.out.println("The principal is $" + (int)pr); //*Shows the principle amount in $ value. System.out.println("The annual interest rate is " + format(annRate * 100, 2) +"%"); System.out.println("The term is " + years + " years"); //*Term is normally in years. System.out.println("Your monthly payment is $" + mpayment); //*Shows output of monthly payment. System.exit(0); //*System exits nice and quietly } }

This post has been edited by **onecpudr**: 08 March 2009 - 06:04 PM