| | |
Writing Mortgage program in Java
Please support our Java advertiser: Programming Forums - DaniWeb Sister Site
![]() |
•
•
Join Date: Oct 2006
Posts: 3
Reputation:
Solved Threads: 0
/*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){}
}
}
}
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){}
}
}
}
•
•
Join Date: Jan 2009
Posts: 2
Reputation:
Solved Threads: 0
[QUOTE=PPaul1;263763]/*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*/
[You needed a second bracket behind balance and interest in your printout line. ]
java Syntax (Toggle Plain Text)
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 Ancient Dragon; Jan 16th, 2009 at 6:32 pm. Reason: add code tags
![]() |
Similar Threads
- creating an instant messenger program in java (Java)
- Mortgage Program (Java)
- Finding the first number char in a string (Java)
- Java Multidimensional Arrays (Java)
- java problem with creating arrays (Java)
- Mortgage Program help (Java)
- I need an exampls program in java to store image datatype in ms-sql (MS SQL)
Other Threads in the Java Forum
- Previous Thread: How to use arrow keys to move applet? Urgent help needed.
- Next Thread: Access through ODBC
Views: 4512 | Replies: 2
| Thread Tools | Search this Thread |
Tag cloud for Java
android api apple applet application arguments array arrays automation bidirectional binary birt bluetooth calculator chat class classes client code columns component database designadrawingapplicationusingjavajslider draw eclipse editor error errors event exception expand file fractal game givemetehcodez graphics gui guidancer helpwithhomework html ide image inetaddress input integer intellij j2me java javamicroeditionuseofmotionsensor javaprojects jme jmf jni jpanel julia link linux list loop map method methods mobile mobiledevelopmentcreatejar myaggfun netbeans newbie number object oracle plazmic print problem program programming project recursion scanner screen server set signing size smart sms smsspam socket sort sql string subclass support swing test threads time transfer tree webservices windows





