Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Mortgage calculation in java programming language

Posted on 2004-08-27
14
Medium Priority
?
336 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
How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

 
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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

It’s time for spooky stories and consuming way too much sugar, including the many treats we’ve whipped for you in the world of tech. Check it out!
With so many activities to perform, Exchange administrators are always busy in organizations. If everything, including Exchange Servers, Outlook clients, and Office 365 accounts work without any issues, they can sit and relax. But unfortunately, it…
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
Suggested Courses

618 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