Solved

Mortgage calculation in java programming language

Posted on 2004-08-27
14
326 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Convertion SDK Vc++ to Delphi - fingerprint reader 5 790
Creating a blank copy of a TClientDataSet 1 1,145
Search the database TADOQuery and TVirtualStringTree 3 613
SQL Query issue 13 402
When we talk about DevOps toolchains, I sometimes wonder how many people really get what we’re talking about. I don’t know if it’s just semantics or tone or something else, but sometimes I think it just sounds like buzzword sausage. So it’s always …
We need a new way to communicate time sensitive or critical info.   The best part of my role at xMatters is visiting our clients all over the world to learn about how they operate their businesses, share insights that xMatters has gleaned across…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.
Need to grow your business through quality cloud solutions? With everything required to build a cloud platform and solution, you may feel like the distance between you and the cloud is quite long. Help is here. Spend some time learning about the Con…

939 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

16 Experts available now in Live!

Get 1:1 Help Now