Solved

Mortgage calculation in java programming language

Posted on 2004-08-27
14
327 Views
Last Modified: 2010-04-16
$200,000 loan amount
5.75% interest rate
30 year term
0
Comment
Question by:Helenthejewel
  • 5
  • 2
  • 2
  • +2
14 Comments
 

Author Comment

by:Helenthejewel
ID: 11919354
<email removed by mlmcc PE>>I do appreciate the help.
0
 
LVL 11

Expert Comment

by:Jase-Coder
ID: 11920489
write some pusedo code or attempt to write some code here and I'll help you. I cant write the progrm because it sounds like homeork
0
 

Author Comment

by:Helenthejewel
ID: 11921908
import java.awt.*;
 Class Mortgage  {
  public static void main (String[] args)  {
 static int years = 30;  
 static double amount = 200000;  
 static double rate = 5.75;    
 
  //My first attempt to write a Java program
 }    
  {"I'm in main", "My
             mortgage amount has been hard-coded..."
 {
 {
 mortgage_amount= $200,000;
 }
 //No down payment The monthly factor
 function set_interest(5.75)  System out.printin(.0575/12);
  {
 interest_rate=form.interest_rate.value;
 }
 {
 function set_term(30 years)  System out.printin(360*12);
 }
 {term=form.term.value; System out.printn(200,000*0.0048)
  }
0
Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

 
LVL 11

Assisted Solution

by:Jase-Coder
Jase-Coder earned 62 total points
ID: 11922003
you could write a function that

I assume the interest is monthly

  for(int i = 0; i < years; i++)
  {
     for(int j = 0; j < 12; j++)
     {
         monthly_payment = amount * rate; /* calculates the interest to be paid */
         System.out.println("Total interest paid this month" + monthly_payment);
          total_paid += monthly_payment; /*holds the total amount paid */
         
     }
     System.out.println("total loan paid back after " + i + " years is " + total_paid);
   }

That calculates the interest for the 30 year period. If you have an amount they have to pay say, £100 a month plus the interest

add the following line below monthly payment

month_payment += 100;        
0
 

Author Comment

by:Helenthejewel
ID: 11922042
I have been working with it day and night.  I am using JProPro.  So far I have revised to the following point:  Please check
import java.math.*;
import java.text.*;
import java.util.*;


public class mortgage{
   
 static NumberFormat n = NumberFormat.getCurrencyInstance();

    static int yterm = 30;            // Variable for length of term in years
    static double price = 200000;    // Variable for total amount of mortgage
    static double rate = 5.75;        // Variable for interest rate
    static double mrate = rate/100;
    static double payment = price*((mrate)/(12)+((mrate)/(12))/(Math.pow((1+(mrate)/12),(yterm*12))-1));
                               
                               
  public static void main(String[] args) throws Exception {

       
       
    int term = 360;
    double interestDue, amtApplied;      

   while (term > 0) {
      if(term == 300)
      break;
        interestDue = (price * (rate/100)) / 12;
        amtApplied = payment - interestDue;
        price = price - amtApplied;
       


System.out.println("Payment # "  + term
            + "  Principle=" + n.format(amtApplied)
            + "  Interest=" + n.format(interestDue)
            + "  Balanace=" + n.format(price));
        --term;
    return --term;
 }
   

   while (term > 0) {
      if(term == 240)
      break;
        interestDue = (price * (rate/100)) / 12;
        amtApplied = payment - interestDue;
        price = price - amtApplied;
       


System.out.println("Payment # "  + term
            + "  Principle=" + n.format(amtApplied)
            + "  Interest=" + n.format(interestDue)
            + "  Balanace=" + n.format(price));
        --term;
   
 }
0
 

Author Comment

by:Helenthejewel
ID: 11922064
In your example:  I received the following error:

File "C:\WINDOWS\Temporary Internet Files\Content.IE5\BZGXQZIA\java24.java" Line 1: Syntax Error
0
 

Author Comment

by:Helenthejewel
ID: 11922096
In the second version, I could not get it to compile can you reaccess that version Please!
0
 

Expert Comment

by:GaryStanton414
ID: 12077014
Can you explain what exactly you are calculating and how you need to calculate it. It is hard to know if you are doing it correctly unless we know exactly what you need to do.
0
 

Accepted Solution

by:
GaryStanton414 earned 63 total points
ID: 12077488
while (term > 0) {
      if(term == 300)
     break;
        interestDue = (price * (rate/100)) / 12;
        amtApplied = payment - interestDue;
        price = price - amtApplied;
       


            System.out.println("Payment # "  + term
            + "  Principle=" + n.format(amtApplied)
            + "  Interest=" + n.format(interestDue)
            + "  Balanace=" + n.format(price));
        --term;
    return --term;
 }

*******************************************************************
Instead of the above why not use:

while (term > 300) {
     
        interestDue = (price * (rate/100)) / 12;
        amtApplied = payment - interestDue;
        price = price - amtApplied;
       


            System.out.println("Payment # "  + term
            + "  Principle=" + n.format(amtApplied)
            + "  Interest=" + n.format(interestDue)
            + "  Balanace=" + n.format(price));
        --term;
   
 }

***********************************************************************************
There is no need for the:

if(term == 300) break;

Just change the condition in the while loop as i have shown. This has the same effect...the loop only goes untill term equals 300

Or better yet dont bother with the while loop. A for loop is designed to do what you are doing:


for (; term > 300; term--) {
     
        interestDue = (price * (rate/100)) / 12;
        amtApplied = payment - interestDue;
        price = price - amtApplied;
       


            System.out.println("Payment # "  + term
            + "  Principle=" + n.format(amtApplied)
            + "  Interest=" + n.format(interestDue)
            + "  Balanace=" + n.format(price));
       
 }

That would also have the same effect.

Also I dont understand why you are using 2 while loops. You seem to be doing exactly the same thing in each one. So why not just do the following...it seems to me that this will have the same effect:


for (; term > 240; term--) {
     
        interestDue = (price * (rate/100)) / 12;
        amtApplied = payment - interestDue;
        price = price - amtApplied;
       


            System.out.println("Payment # "  + term
            + "  Principle=" + n.format(amtApplied)
            + "  Interest=" + n.format(interestDue)
            + "  Balanace=" + n.format(price));
       
 }

*****************************************************************************
Also I dont understand why you need:

return --term

This is only used in methods to pass a value back to the method which called it. There is no reason I can think of why you would want to return a value in the main method as there is nothing to return to.

Its a while since iv done any java so if i am wrong please tell me, but as far as I know im correct.
0
 
LVL 17

Expert Comment

by:Wim ten Brink
ID: 12275450
Ehm, if this question gets closed and the other question in this topic area too then there are no more open questions in this topic area anymore. How can we, experts, earn any points if there just aren't any questions anymore? ;-)

Oh, just close it. No objections here. I'm just nagging a bit since this topic area seems dead and buried by now. :-(
0
 
LVL 100

Expert Comment

by:mlmcc
ID: 12282153
I understand the frustration.  It is EE policy to close questions that don't have recent comments in them.  I think you will find that many Pascal questions are school or training related and once an answer is received they may or may not get closed.

Keep an eye on the TA it may get more questions.  If you look at the answered questions you will notice there is a lag between questions.

mlmcc
0

Featured Post

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Read about the ways of improving workplace communication.
Color can increase conversions, create feelings of warmth or even incite people to get behind a cause. If you want your website to really impact site visitors, then it is vital to consider the impact color has on them.
This is used to tweak the memory usage for your computer, it is used for servers more so than workstations but just be careful editing registry settings as it may cause irreversible results. I hold no responsibility for anything you do to the regist…
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…

813 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now