944,087 Members | Top Members by Rank

Ad:
  • Java Discussion Thread
  • Unsolved
  • Views: 8309
  • Java RSS
Oct 15th, 2006
0

Writing Mortgage program in Java

Expand Post »
/*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){}

}
}
}
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
PPaul1 is offline Offline
3 posts
since Oct 2006
Oct 15th, 2006
0

Re: Writing Mortgage program in Java

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.
Reputation Points: 22
Solved Threads: 11
Posting Whiz in Training
DavidRyan is offline Offline
229 posts
since Jul 2006
Jan 16th, 2009
0

Re: Writing Mortgage program in Java

[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*/

java Syntax (Toggle Plain Text)
  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
Reputation Points: 10
Solved Threads: 0
Newbie Poster
Jearline is offline Offline
2 posts
since Jan 2009

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Java Forum Timeline: How to use arrow keys to move applet? Urgent help needed.
Next Thread in Java Forum Timeline: Access through ODBC





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC