Writing Mortgage program in Java

Please support our Java advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: Oct 2006
Posts: 3
Reputation: PPaul1 is an unknown quantity at this point 
Solved Threads: 0
PPaul1 PPaul1 is offline Offline
Newbie Poster

Writing Mortgage program in Java

 
0
  #1
Oct 15th, 2006
/*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){}

}
}
}
Reply With Quote Quick reply to this message  
Join Date: Jul 2006
Posts: 229
Reputation: DavidRyan is an unknown quantity at this point 
Solved Threads: 11
DavidRyan's Avatar
DavidRyan DavidRyan is offline Offline
Posting Whiz in Training

Re: Writing Mortgage program in Java

 
0
  #2
Oct 15th, 2006
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.
Please anyone, correct me if I am wrong. It is the best way for me to learn.
Reply With Quote Quick reply to this message  
Join Date: Jan 2009
Posts: 2
Reputation: Jearline is an unknown quantity at this point 
Solved Threads: 0
Jearline Jearline is offline Offline
Newbie Poster

Re: Writing Mortgage program in Java

 
0
  #3
Jan 16th, 2009
[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*/

  1. import java.text.*;
  2. public class Mortgagepayment
  3. {
  4. public static void main(String[] args)
  5. {
  6. //declaration statements
  7. int length=30; // 30 year mortgage
  8. double balance =200000.00; //amount borrowed
  9. double rate=5.75;
  10. double monthly_payment = 0.00;
  11. double monthly_principal=0.00;
  12. double monthly_interest = 0.00;
  13. NumberFormat currency=NumberFormat.getCurrencyInstance();
  14. double y_rate = (rate /100/12);
  15. double monthly_payments = balance * ( y_rate / (1 - Math.pow((1+y_rate),-1*(length*12) ) ));
  16. y_rate = (rate/100)/12;
  17. System.out.println("\t\tMortgage Payment Formula");
  18. System.out.println("\t\tBalance own is $200,000");
  19. System.out.println("\t\tYearly interest rate is 5.75%");
  20. System.out.println("\t\tThe length of loan is 30 years\n");
  21.  
  22. // start of loop to calculate interest paid and balance owe
  23. // print statement as balance increment,as interest increment
  24. for (int mpi =1; mpi<=length*12; mpi++) { // months of payment being decrimented start counter
  25. monthly_interest = (balance*y_rate);
  26. balance = (balance - monthly_principal);
  27. monthly_principal = (monthly_payment - monthly_interest);
  28. System.out.println("Balance is $" + currency.format(balance));
  29. System.out.println("Interest paid is $" + currency.format(monthly_interest));
  30.  
  31. try {Thread.sleep(10);} catch (InterruptedException e){}
  32.  
  33. }
  34. }
  35. }
[You needed a second bracket behind balance and interest in your printout line. ]
Last edited by Ancient Dragon; Jan 16th, 2009 at 6:32 pm. Reason: add code tags
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:




Views: 4512 | Replies: 2
Thread Tools Search this Thread



Tag cloud for Java
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC