import java.text.DecimalFormat;
public class MortgageCalculator4 {
/* Method main - This ia the main body of the program
*/
public static void main(String[] args) {
/* The following Java code was taken from:
* Sun Microsystems, Inc.. (2009). The Java Tutorials: Learning the Java Language: Language Basics
* Retrieved October 24, 2009,
* from
http://java.sun.com/docs/books/tutorial/java/nutsandbolts/arrays.html
*/
//Creates the array for interest rates and loan amounts
double [][] Loan1Array = {{5.35},
{7}};
double [][] Loan2Array = {{5.50},
{15}};
double [][] Loan3Array = {{5.75},
{30}};
/* The following information was taken from:
* (2009). Mortgage Calculations -- How It Works. Hugh Chou.
* Retrieved October 10, 2009, from
http://www.hughchou.org/calc/formula.html
*/
//Initial amount of the loan
double P = 200000;
//Formula used to calculate the yearly interest based on the data
//in the first array
double L1 = ((Loan1Array[1][0]) * (12));
//Formula used to calculate the number of months on the loan
double L2 = ((Loan1Array[0][0]) / (12 * 100));
//Formula used to calculate the actual monthly payment
double P1 = P * (L2 / (1 - (Math.pow((1 + L2), (L1 * -1)))));
//Formats the number to two decimals
DecimalFormat twoDigits = new DecimalFormat("#0.00");
//Statement to print out the payment amount
System.out.println("The Mortgage Payment Amount for the First Loan (7 years, 5.35%) is: " + twoDigits.format(P1));
//Formulas used to calculate the yearly interest and months
//on the loan based on the data in the second array;
//this section updates the old formulas with new data
double L3 = ((Loan2Array[1][0]) * (12));
double L4 = ((Loan2Array[0][0]) / (12 * 100));
double P2 = P * (L4 / (1 - (Math.pow((1 + L4), (L3 * -1)))));
System.out.println("The Mortgage Payment Amount for the Second Loan (15 years, 5.5%) is: " + twoDigits.format(P2));
//Formulas used to calculate the yearly interest and months
//on the loan based on the data in the third array;
//this section updates the old formulas with new data
double L5 = ((Loan3Array[1][0]) * (12));
double L6 = ((Loan3Array[0][0]) / (12 * 100));
double P3 = P * (L6 / (1 - (Math.pow((1 + L6), (L5 * -1)))));
System.out.println("The Mortgage Payment Amount for the Third Loan is (30 years, 5.75%) : " + twoDigits.format(P3));
}
}