# Mortgage Calculator

• 09-05-2011, 08:05 PM
missmara77
Mortgage Calculator
Hi Can some please help me with this... i dont know where i went wrong/ error is at the bottom/ im using textpad

/**************************************
* Formula to calculate monthly payment
* ************************************
*
* Principal + InterestMontly
* MonthlyPayment = --------------------------------------------
* 1 - (1+ InterestMonthly) ^ -NumberOfPayments
*
*
*Principal = The initial amount of the loan
*InterestYearly = The annual interest rate (from 1 to 100 percent)
*InterestMonthly = monthly interest in decimal form = interestYealy / (12 * 100)
*LengthInYears = the length (in years) of the loan
*NumberOfPayments = number of months over which loan is amortized = L * 12
*
*
*
*
*InterestMonthly = InterestYearly / (12.0*100.0)
*NumberOfPayments = LengthInYears *12
*MonthlyPayment = (Principal * InterestMonthly) / (1.0 - (Math.pow(1.0 + InterestMonthly, - NumberOfPayments)))
*
*
*
*
*Importing Date class
*/

import java.text.NumberFormat;
import java.util.Date;

//Demonstrates a public Class
// File name is CalculateMonthlyPayment.java
public class CalculateMonthlyPayment
{
// Calculate the ComputeMonthlyPayment method
public static void main(String[] args){
// Initial Conditions
//declares variable and array for different laon and defines hard coded values
double principal = 200000;
double interestYearly = 0.0535;
int lengthInYears = 7;
// principal is the amount of the loan
// lengthInYears is the term of the loan in years

// print start infomation
Date todaysDate = new Date();
System.out.println ("Week 2 Home work YOMARA 1277: SR-mf-0003");
System.out.println ("Executed on: " + todaysDate);

// calculate monthly payment and display
for(int i=0;i<3;i++)
{
double monthlyPayment = ComputeMonthlyPayment(principal, interestYearly, lengthInYears);
DisplayMonthlyPayment(principal, lengthInYears, interestYearly, monthlyPayment);
}

}

/************************************************
* Method to Display Payment
************************************************** ****/
public static void DisplayMonthlyPayment(double total, int years, double rate, double monthlyPayment)
{
// use currency format for current default locale
NumberFormat nf = NumberFormat.getCurrencyInstance();
System.out.println ("");
System.out.println ("For the loan amount " + nf.format(total) + " over " + years +
" years term at " + (rate * 100) + "% interest rate");
System.out.println ("Monthly Payment Amount is: " + nf.format(monthlyPayment));
}

/************************************************
* Method to calculate and Return the Monthly Payment
************************************************** ****/
public static double ComputeMonthlyPayment(double principal, double interestYearly, int lengthInYears)
{
double interestMonthly = 0; // Interest paid Each Month
double numberOfPayments = 0;

interestMonthly = ComputeMonthlyInterest( interestYearly );
numberOfPayments = lengthInYears * 12.0;
// Apply the method outlined above
// Demonstrates using the power function of the Math class
return (principal * interestMonthly) / (1.0-(Math.pow((1.0 + interestMonthly),-numberOfPayments)));
}

/*****************************************
* Method to compute the Monthly Interest
**********************************************/
public static double ComputeMonthlyInterest( double interestYearly)
{
return interestYearly / (12.0);
}

}

C:\Users\Alexa baby\Documents\Document1.java:37: class CALCULATEMONTHLYPAYMENT is public, should be declared in a file named CALCULATEMONTHLYPAYMENT.java
public class CALCULATEMONTHLYPAYMENT
^
1 error

Tool completed with exit code 1
• 09-05-2011, 08:16 PM
Fubarable
Re: Mortgage Calculator