?
Solved

Mortgage Payment Calculator

Posted on 2006-07-18
8
Medium Priority
?
302 Views
Last Modified: 2012-06-09
I am attempting to incorporate a 7 year loan as well as a 15 year loan into the following code and these two loans would have different interest rates than the 30 year loan I have already programmed.  I need some assistance on how to incorporate a 7 year loan @ 5.35% and a 15 year loan @ 5.5% into my current code which compiles very nicely:

import java.io.*;
import java.util.Date;
import java.text.DecimalFormat;


public class Mortgage

{
public static void main(String[] args)


      {

Date currentDate = new Date();
//Date Constructor
DecimalFormat decimalPlaces = new DecimalFormat("$0.00");

//Declaring Variables
double dPrincipal = 200000.00; //Total Loan or Principal Amount
double dInterest = .0575;  //Interest Rate all Payments are Calculated at
double dTerm = 12*30; //Total Term of Loan in Months
double dMonthlyInterest = dInterest/12;


//Declaring Variables

final double dMonthly = dPrincipal * (dMonthlyInterest / (1 - Math.pow(1 + dMonthlyInterest,-dTerm)));
//The above formula calculates and determines the exact monthly payment based upon input

//The following code will display the output of the program
System.out.println("\t\t" + currentDate);
System.out.println("\t\tThe Total Loan Amount is: " + decimalPlaces.format(dPrincipal));
System.out.println("\t\tThe Calculated Interest Rate is: " + dInterest);
System.out.println("\t\tThe Total Number of Monthly Payments is: " + dTerm);
System.out.println("\t\tThe Total Monthly Payment is: " + decimalPlaces.format(dMonthly));

      }

}

Any help would be greatly appreciated.  Thank you
0
Comment
Question by:waw9667
[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
  • 3
8 Comments
 
LVL 10

Expert Comment

by:mukundha_expert
ID: 17132186
do you mean that for the fixed principal ( 200000 ), you have to show thw loan amount , interest rate, monthly payment for 30yrs, 15 yrs, 7 yrs resply.
0
 
LVL 10

Expert Comment

by:mukundha_expert
ID: 17132218
if that is the case,

add,

double dInt[] = { 0.0535, 0.055, 0.0575 } ;
double dTerms[] = { 7,15,30 } ;
      
      
      for ( int i = 0 ; i < 3 ; i ++ )
      {
      //Declaring Variables
      double dPrincipal = 200000.00; //Total Loan or Principal Amount
      double dInterest = dInt [ i ];  //Interest Rate all Payments are Calculated at
      double dTerm = 12* dTerms [i ]; //Total Term of Loan in Months
      double dMonthlyInterest = dInterest/12;
//calculate and print
}
0
 

Author Comment

by:waw9667
ID: 17132245
Only a single payment for each loan term though.  My current code shows what a $200,000 loan monthly payment would be on a 30 year loan at 5.75% interest rate.  If you compile what I already have, I basically need to do the same exact thing for a 7 year loan at 5.35% interest rate and a 15 year loan at 5.5% interest rate.  To answer your question,
yes.  However, I already have the 30 year portion completed.
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 10

Expert Comment

by:mukundha_expert
ID: 17132308
     double dInt[] = { 0.0535, 0.055, 0.0575 } ;
      double dTerms[] = { 7,15,30 } ;
      
      
      for ( int i = 0 ; i < 3 ; i ++ )
      {
      //Declaring Variables
      double dPrincipal = 200000.00; //Total Loan or Principal Amount
      double dInterest = dInt [ i ];  //Interest Rate all Payments are Calculated at
      double dTerm = 12* dTerms [i ]; //Total Term of Loan in Months
      double dMonthlyInterest = dInterest/12;
      
      
      //Declaring Variables
      
      final double dMonthly = dPrincipal * (dMonthlyInterest / (1 - Math.pow(1 + dMonthlyInterest,-dTerm)));
      //The above formula calculates and determines the exact monthly payment based upon input
      
      //The following code will display the output of the program
      System.out.println("\t\t" + currentDate);
      System.out.println("\t\tThe Total Loan Amount is: " + decimalPlaces.format(dPrincipal));
      System.out.println("\t\tThe Calculated Interest Rate is: " + dInterest);
      System.out.println("\t\tThe Total Number of Monthly Payments is: " + dTerm);
      System.out.println("\t\tThe Total Monthly Payment is: " + decimalPlaces.format(dMonthly));
      
      System.out.println( "" ) ;
    }


have you tried this,
0
 

Author Comment

by:waw9667
ID: 17132428
Did I add something in the wrong place ?  It contains three errors.  I probably did.

import java.io.*;
import java.util.Date;
import java.text.DecimalFormat;


public class Mortgage

{
public static void main(String[] args)
double dInt[] = {0.0535,0.055,0.0575};
double dTerms[] = {7,15,30};

for ( int i = 0 ; i < 3 ; i ++ )
      {

Date currentDate = new Date();
//Date Constructor
DecimalFormat decimalPlaces = new DecimalFormat("$0.00");

//Declaring Variables
double dPrincipal = 200000.00; //Total Loan or Principal Amount
double dInterest = dInt[i];  //Interest Rate all Payments are Calculated at
double dTerm = 12*dTerms[i]; //Total Term of Loan in Months
double dMonthlyInterest = dInterest/12;
//Calculate and print


//Declaring Variables

final double dMonthly = dPrincipal * (dMonthlyInterest / (1 - Math.pow(1 + dMonthlyInterest,-dTerm)));
//The above formula calculates and determines the exact monthly payment based upon input

//The following code will display the output of the program
System.out.println("\t\t" + currentDate);
System.out.println("\t\tThe Total Loan Amount is: " + decimalPlaces.format(dPrincipal));
System.out.println("\t\tThe Calculated Interest Rate is: " + dInterest);
System.out.println("\t\tThe Total Number of Monthly Payments is: " + dTerm);
System.out.println("\t\tThe Total Monthly Payment is: " + decimalPlaces.format(dMonthly));

      }
}

0
 
LVL 10

Accepted Solution

by:
mukundha_expert earned 2000 total points
ID: 17132534
>>public static void main(String[] args)

add one brace here,
public static void main(String[] args)
{

then one at the last,

System.out.println("\t\tThe Total Monthly Payment is: " + decimalPlaces.format(dMonthly));
}
}
}
0
 

Author Comment

by:waw9667
ID: 17132604
Thanks again for sharing your incredible knowledge and wisdom with a beginner like myself.  I work in the IT field but this programming thing is just too new for me right now.  Have a great day !!
0
 
LVL 10

Expert Comment

by:mukundha_expert
ID: 17132644
:)
Cheers
0

Featured Post

Enroll in October's Free Course of the Month

Do you work with and analyze data? Enroll in October's Course of the Month for 7+ hours of SQL training, allowing you to quickly and efficiently store or retrieve data. It's free for Premium Members, Team Accounts, and Qualified Experts!

Question has a verified solution.

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

By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.
Suggested Courses

649 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