``````/**
Programmer: Jennifer Mercer
Date: 12/12/2011
Course: PRG/420
File: Calculator.java
Requestor: Dwain Hammer Billings MT
Request Description:
Write the program in Java (without a graphical user interface) and have it calculate the payment amount for 3 mortgage loans:
- 7 year at 5.35%
- 15 year at 5.5%
- 30 year at 5.75%
Use an array for the different loans. Display the mortgage payment amount for each loan.
Display the mortgage payment amount for each loan and then list the loan balance and interest
paid for each payment over the term of the loan.
Use loops to prevent lists from scrolling off the screen.
Reference for JavaScript:NScraps. (2011). Retrieved from http://nscraps.com/Java/768-program-calculate-mortgage-payments-java.htm

*/
import java.math.*;
import java.text.*;

class MortgageCalculator {
public static void main(String arguments[]) {

//Program Variables using array
double []terms = {7,15,30};//Mortgage Loan Term
double []Rates = {0.0535, 0.055, 0.0575};//Mortgage Loan's Interest Rate
double loan = 200000;//Loan Amount

double term, interestRate; //Temporary variables to make things generic and clearer

DecimalFormat df = new DecimalFormat("\$###,###.00"); //Formatting the output

//for each term and Rate starting from the first location of each array terms[] and Rates[]
for (int i=0;i<terms.length;i++){
//Calculates the Payment per month to be paid under mortgage scheme One
interestRate=Rates[i]; //take value from the array Rates[] to a temporary variable
term=terms[i]; //take value from the array terms[] to a temporary variable
double monthlyRate = (interestRate/12); //derive the monthly interest rate
//calculate the discount factor
double discountFactor = (Math.pow((1 + monthlyRate), term) -1) / (monthlyRate * Math.pow((1 + monthlyRate), term));
double payment1 = loan / discountFactor; //calculate payable amount per month
//Output for mortage scheme One
System.out.println("The Loan amount is:"+df.format(loan)+"\n");
System.out.println("The intrest rate is:"+interestRate*100+"%");
System.out.println("The term of the loan is:"+term/12+" years.");
System.out.println("Monthly Payment Amount: " + df.format(payment1)+"\n");

//Refrence for code: EHow. (1999). Retrieved from http://www.ehow.com/way_6031409_java-amortization-calculator-code.html

double interest ;
double principal ;
int numPayments ;
double balance ;
double payment ;

class AmortizationSchedule {double i, double p, int n} {
interest = i ;
principal = p ;
numPayments = n ;
}

public void printAmoritizationSchedule () {
double curInterest = 0, curPrincipal = 0 ;
double totalPayments = 0, totalPrincipal = 0, totalInterest = 0 ;

payment = (principal * interest) / (1 - Math.pow((1 + interest), -numPayments)) ;
balance = principal ; double curInterest = 0 ;
System.out.println ("Period, Payment, Principal, Interest, Balance") ;

for (int period = 1 ; period <= numPayments ; period++) {

curInterest = balance * interest ;

if (period == numPayments) {
payment = balance + curInterest ;
curPrincipal = payment - curInterest ;
balance -= curPrincipal ;
System.out.println (period + ", " + payment + ", " + curPrincipal + ", " + curInterest + ", " + balance) ;

totalPayments += payment ;
totalPrincipal += curPrincipal ;
totalInterest += curInterest ;

System.out.println ("Totals, " + totalPayments + ", " + totalPrincipal + ", " + totalInterest) ;
}
printAmoritizationSchedule();
}
}
}
}``````

Check the pairing of the {}s in your code.

Also the code is not indented according to standards. Code nested within {} should be indented 3-4 spaces for each level of nesting of {}

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.