import java.util.Scanner;
public class MortgageCalc{
public static void main(String args[]){
Scanner LoanInfo = new Scanner (System.in);
double LoanAmount, InterestRate, MonthlyPayment, LoanTotal, LoanDuration, InterestRatePerMonth, NumberofPayments;
System.out.print("Mortgage Calc > Enter the Loan Ammount($): ");
LoanAmount = LoanInfo.nextDouble(); //When information is entered it is stored as LoanAmount.
System.out.print("Mortgage Calc > Enter the Loan Period (YRS): ");
LoanDuration = LoanInfo.nextInt(); //When information is entered it is stored as LoanDuration.
System.out.print("Mortgage Calc > Enter the Loan Interest Rate(%): ");
InterestRate = LoanInfo.nextDouble(); //When information is entered it is stored as InterestRate.
InterestRatePerMonth = (InterestRate/100)/12; // Converts the entered number into a percentage then divides by 12 to get the interest rate per month.
NumberofPayments = LoanDuration*12; // Converts the LoanDuration in (yrs) to number of monthly payments.
MonthlyPayment = LoanAmount*(Math.pow((1+InterestRatePerMonth), NumberofPayments))*InterestRatePerMonth/((Math.pow((1+InterestRatePerMonth),(NumberofPayments)))-1);
//Calculation Used: M = P[i(1+i)^n]/[(1+i)^n-1]
// M = Monthly Payment, i = InterestRate/12 (for 12 months per year), n = Number of Payments (This is equivalent to LoanDuration * 12 months in a year)
// P = LoanAmount
System.out.println("");
System.out.print("Mortgage Calc > Monthly Loan Payment($): ");
System.out.print(Math.round(MonthlyPayment*100)/100f); // Rounds the MonthlyPayment display to 2 decimal places.
}
//Variables Declared
int i=0,
month;
This post has been edited by Dogstopper: 09 April 2010 - 08:11 PM
Reason for edit:: fixed code tags

New Topic/Question
Reply
MultiQuote








|