| | |
Mortgage Program
Please support our Java advertiser: Programming Forums - DaniWeb Sister Site
![]() |
•
•
Join Date: Oct 2006
Posts: 3
Reputation:
Solved Threads: 0
I'm trying to show the balance and interest paid for each month. The balance should go down with each loop until balance is paid in full. The balance will go down but with the wrong amount I don't know how to put an loop in here that will say balance payed in full at the end of the code. The interest paid should go up with each loop , it goes up with the wrong amount
/*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.*/
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){}
}
}
}
/*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.*/
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){}
}
}
}
Last edited by PPaul1; Oct 16th, 2006 at 7:18 am. Reason: personal info
•
•
•
•
balance = (balance - monthly_principal);
monthly_principal = (monthly_payment - monthly_interest);
As far as a print statement for paid in full, simply add a print statement after the loop.
Java Programmer and Sun Systems Administrator
----------------------------------------------
Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.
--Brian Kernighan
----------------------------------------------
Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.
--Brian Kernighan
![]() |
Similar Threads
- Writing Mortgage program in Java (Java)
- C/C++ Mortgage program not working...I need some serious help...i'm a newbie (C++)
- Newbie needs help with mortgage program (C++)
- Mortgage Program help (Java)
Other Threads in the Java Forum
- Previous Thread: Beginner looking for help with Javascript
- Next Thread: array problem in java "Snake game"
| Thread Tools | Search this Thread |
Tag cloud for Java
affinetransform android api apple applet application arc arguments array arrays automation binary bluetooth businessintelligence chat class classes client code component database desktop draw ebook eclipse equation error event exception fractal game givemetehcodez graphics gui html ide image input integer intellij intersect iphone j2me java javaexcel javaprojects jmf jni jpanel julia linked linux list loop loops mac main map method methods mobile netbeans newbie number online open-source oracle parameter print problem program programming project properties recursion reference replaysolutions reporting rotatetext scanner screen scrollbar server set size sms socket sort sql string superclass swing template test threads time tree windows working xstream






