Welcome to Dream.In.Code
Become a Java Expert!

Join 150,369 Java Programmers for FREE! Get instant access to thousands of Java experts, tutorials, code snippets, and more! There are 1,807 people online right now. Registration is fast and FREE... Join Now!




mortgage calculator (homework problem)

 
Reply to this topicStart new topic

mortgage calculator (homework problem)

eamado01
24 Jan, 2008 - 10:32 AM
Post #1

New D.I.C Head
*

Joined: 24 Jan, 2008
Posts: 4

Write the program in Java (without a graphical user interface) using a loan amount of $200,000 with an interest rate of 5.75% and a 30 year term. Display the mortgage payment amount and then list the loan balance and interest paid for each payment over the term of the loan. If the list would scroll off the screen, use loops to display a partial list, hesitate, and then display more of the list.

It runs but... it doesn't subtract the amount to $0.00
if someone can take a look and help me out, that would be Great!

Thanks.


CODE

import java.util.*;
import java.text.*;
public class mortgage2
{
    public static void main(String[]args)
    {
    
// declare variable
        System.out.println("Mortgage1\n");
        double loan=200000.00;// P
        double term=30; // L
        double interest=5.75; //I
        double monthly_payment= 0; //M
        double monthly_interest= 0;  //J
        double months;  //N
        double Current_Monthly_Interest_Rate = 0;  // H
        double Principal_Paid_Current_Month = 0;  //C
        double New_Balance_Of_Principal = 0;      //Q
        int linecounter = 30;    
        
//Displays the mortgage calculator
System.out.println("Mortgage Calculator");
System.out.println("The loan amount is $200,000");
System.out.println("The term of the loan is 30 years");
System.out.println("The interest rate applied to the loan is 5.75%");
System.out.println();

{
        
        
// calculate monthly interest        
        monthly_interest=interest/(12*100);  //J
    
System.out.println("monthly_interests: " + monthly_interest);    
// calculate months    
        months=term*12;  //N
System.out.println("month: " + months);
    
// calculate monthly payment    
        monthly_payment=monthly_interest*loan/
                (1-Math.pow( (1+monthly_interest), -months) );
                
                
    
    
    
// display monthly payment    
        System.out.println("\n\n\t Monthly Payment is: " + monthly_payment);
        System.out.println();
    
for (int k =1; k<=360; k++)
{

Current_Monthly_Interest_Rate = (loan * monthly_interest);
System.out.println("Current: " +Current_Monthly_Interest_Rate);
Principal_Paid_Current_Month =(monthly_payment - Current_Monthly_Interest_Rate);
System.out.println("Principal: " +Principal_Paid_Current_Month);
New_Balance_Of_Principal =(loan -  Principal_Paid_Current_Month);
System.out.println("new balance: " +New_Balance_Of_Principal);
//display current payment information.

System.out.println("Month= " +k+ "\tBalance = "+
New_Balance_Of_Principal + "   interest = " + Current_Monthly_Interest_Rate);


linecounter++;
if(linecounter ==15)
{

for(int i=1;i<10000;i++)
for(int j=1;j<1000000; j++);
linecounter=0;
System.out.println();

loan = New_Balance_Of_Principal;


}
}
}
}
}
~edit: added code tags PB

This post has been edited by PennyBoki: 24 Jan, 2008 - 10:48 AM
User is offlineProfile CardPM
+Quote Post

PennyBoki
RE: Mortgage Calculator (homework Problem)
24 Jan, 2008 - 11:22 AM
Post #2

system("revolution");
Group Icon

Joined: 11 Dec, 2006
Posts: 2,011



Thanked: 7 times
Dream Kudos: 500
Expert In: Java,C++,C

My Contributions
Well all your program does is printing a lot of info.

I don't understand your question, what is that you want us to take a look at?

And please code.gif
User is offlineProfile CardPM
+Quote Post

eamado01
RE: Mortgage Calculator (homework Problem)
24 Jan, 2008 - 11:49 AM
Post #3

New D.I.C Head
*

Joined: 24 Jan, 2008
Posts: 4

When the code is compiled it works... it displays the information. But, when it does the loop, it shows the same amount everytime. I may be missing a formula... or maybe the coding is wrong.

This is the section that has the loop...

Thanks.



CODE

for (int k =1; k<=360; k++)
{

Current_Monthly_Interest_Rate = (loan * monthly_interest);
System.out.println("Current: " +Current_Monthly_Interest_Rate);
Principal_Paid_Current_Month =(monthly_payment - Current_Monthly_Interest_Rate);
System.out.println("Principal: " +Principal_Paid_Current_Month);
New_Balance_Of_Principal =(loan -  Principal_Paid_Current_Month);
System.out.println("new balance: " +New_Balance_Of_Principal);
//display current payment information.

System.out.println("Month= " +k+ "\tBalance = "+
New_Balance_Of_Principal + "   interest = " + Current_Monthly_Interest_Rate);


linecounter++;
if(linecounter ==15)
{

for(int i=1;i<10000;i++)
for(int j=1;j<1000000; j++);
linecounter=0;
System.out.println();

loan = New_Balance_Of_Principal;

User is offlineProfile CardPM
+Quote Post

Martyr2
RE: Mortgage Calculator (homework Problem)
24 Jan, 2008 - 12:02 PM
Post #4

Programming Theoretician
Group Icon

Joined: 18 Apr, 2007
Posts: 5,660



Thanked: 313 times
Expert In: C/C++, Java, VB, VB.NET, C#, PHP, Web Development, HTML & CSS, Javascript

My Contributions
Have you taken a look at my blog? I have an amortization setup for mortgages which generate such a schedule. It also touches on the idea of breaking to zero and provides working code for the big five languages (part of my "definitive" series) which includes Java.

Then after reading and playing with it, you still have questions we can help further.

Martyr2's Programming Underground - Amortization Definitive (C++, C#, Java, VB.NET, PHP)

Enjoy and hope it helps! smile.gif
User is offlineProfile CardPM
+Quote Post

eamado01
RE: Mortgage Calculator (homework Problem)
24 Jan, 2008 - 12:07 PM
Post #5

New D.I.C Head
*

Joined: 24 Jan, 2008
Posts: 4

I am going to take a look

Thanks Martyr2!
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 1/9/09 02:14PM

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter

Live Java Help!

Java Tutorials

Reference Sheets

Java Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month