?
Solved

Mortgage calculation in java programming language

Posted on 2004-08-27
14
Medium Priority
?
335 Views
Last Modified: 2010-04-16
$200,000 loan amount
5.75% interest rate
30 year term
0
Comment
Question by:Helenthejewel
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

 
LVL 11

Assisted Solution

by:Jase-Coder
Jase-Coder earned 248 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 252 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 101

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

On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

Question has a verified solution.

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

A bad practice commonly found during an account life cycle is to set its password to an initial, insecure password. The Password Reset Tool was developed to make the password reset process easier and more secure.
Ready to get certified? Check out some courses that help you prepare for third-party exams.
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
Suggested Courses

765 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