/*Write a Java program without a graphical user interface that calculates and displays the mortgage payment amount given the amount of the mortgage, the term of the mortgage, and the interest rate of the mortgage. In this program, hard code the amount = $200,000, the term = 30 years, and the interest rate = 5.75%. Insert comments in the program to document the program Here what I have so far I need help completing code Thanks*/
import java.text.*;
public class Mortgagepayment
{
public static void main(String[] args)
{
//declaration statements
int length=30; // 30 year mortgage
double balance =200000.00; //amount borrowed
double rate=5.75;
double monthly_payment = 0.00;
double monthly_principal=0.00;
double monthly_interest = 0.00;
NumberFormat currency=NumberFormat.getCurrencyInstance();
double y_rate = (rate /100/12);
double monthly_payments = balance * ( y_rate / (1 - Math.pow((1+y_rate),-1*(length*12) ) ));
y_rate = (rate/100)/12;
System.out.println("\t\tMortgage Payment Formula");
System.out.println("\t\tBalance own is $200,000");
System.out.println("\t\tYearly interest rate is 5.75%");
System.out.println("\t\tThe length of loan is 30 years\n");
// start of loop to calculate interest paid and balance owe
// print statement as balance increment,as interest increment
for (int mpi =1; mpi<=length*12; mpi++) { // months of payment being decrimented start counter
monthly_interest = (balance*y_rate);
balance = (balance - monthly_principal);
monthly_principal = (monthly_payment - monthly_interest);
System.out.println("Balance is $" + currency.format(balance);
System.out.println("Interest paid is $" + currency.format(monthly_interest);
try {Thread.sleep(10);} catch (InterruptedException e){}
}
}
}
Edited
by pyTony: fixed formatting
- 3 Contributors
- forum2 Replies
- 60 Views
- 12 Years Discussion Span
- comment Latest Post by Jearline
Okay, telling us your problem would be useful. Also, please wrap code in the
[code]
code goes here.
[/code] tags.
But I'll bet it is the missing right parentheses in your System.out.println calls.
/*Write a Java program without a graphical user interface that calculates and displays the mortgage payment amount given the amount of the mortgage, the term of the mortgage, and the interest rate of the mortgage. In this program, hard code the amount = $200,000, the term = 30 years, and the interest rate = 5.75%. Insert comments in the program to document the program Here what I have so far I need help completing code Thanks*/
import java.text.*; public class Mortgagepayment { public static void main(String[] args) { //declaration statements int length=30; // 30 year mortgage double balance =200000.00; //amount borrowed double rate=5.75; double monthly_payment = 0.00; double monthly_principal=0.00; double monthly_interest = 0.00; NumberFormat currency=NumberFormat.getCurrencyInstance(); double y_rate = (rate /100/12); double monthly_payments = balance * ( y_rate / (1 - Math.pow((1+y_rate),-1*(length*12) ) )); y_rate = (rate/100)/12; System.out.println("\t\tMortgage Payment Formula"); System.out.println("\t\tBalance own is $200,000"); System.out.println("\t\tYearly interest rate is 5.75%"); System.out.println("\t\tThe length of loan is 30 years\n"); // start of loop to calculate interest paid and balance owe // print statement as balance increment,as interest increment for (int mpi =1; mpi<=length*12; mpi++) { // months of payment being decrimented start counter monthly_interest = (balance*y_rate); balance = (balance - monthly_principal); monthly_principal = (monthly_payment - monthly_interest); System.out.println("Balance is $" + currency.format(balance)); System.out.println("Interest paid is $" + currency.format(monthly_interest)); try {Thread.sleep(10);} catch (InterruptedException e){} } } }
[You needed a second bracket behind balance and interest in your printout line. ]