Solved

Mortgage calculation in java programming language

Posted on 2004-08-27
14
325 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
 
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
Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 

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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

Learn to move / copy / export exchange contacts to iPhone without using any software. Also see the issues in configuration of exchange with iPhone to migrate contacts.
HOW TO: Install and Configure VMware vSphere Hypervisor 6.5 (ESXi 6.5), Step by Step Tutorial with screenshots. From Download, Checking Media, to Completed Installation.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

707 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

22 Experts available now in Live!

Get 1:1 Help Now