waw9667
asked on
Mortgage Payment Calculator
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\tTh e Total Loan Amount is: " + decimalPlaces.format(dPrin cipal));
System.out.println("\t\tTh e Calculated Interest Rate is: " + dInterest);
System.out.println("\t\tTh e Total Number of Monthly Payments is: " + dTerm);
System.out.println("\t\tTh e Total Monthly Payment is: " + decimalPlaces.format(dMont hly));
}
}
Any help would be greatly appreciated. Thank you
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\tTh
System.out.println("\t\tTh
System.out.println("\t\tTh
System.out.println("\t\tTh
}
}
Any help would be greatly appreciated. Thank you
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.
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
}
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
}
ASKER
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.
yes. However, I already have the 30 year portion completed.
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\tTh e Total Loan Amount is: " + decimalPlaces.format(dPrin cipal));
System.out.println("\t\tTh e Calculated Interest Rate is: " + dInterest);
System.out.println("\t\tTh e Total Number of Monthly Payments is: " + dTerm);
System.out.println("\t\tTh e Total Monthly Payment is: " + decimalPlaces.format(dMont hly));
System.out.println( "" ) ;
}
have you tried this,
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\tTh
System.out.println("\t\tTh
System.out.println("\t\tTh
System.out.println("\t\tTh
System.out.println( "" ) ;
}
have you tried this,
ASKER
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\tTh e Total Loan Amount is: " + decimalPlaces.format(dPrin cipal));
System.out.println("\t\tTh e Calculated Interest Rate is: " + dInterest);
System.out.println("\t\tTh e Total Number of Monthly Payments is: " + dTerm);
System.out.println("\t\tTh e Total Monthly Payment is: " + decimalPlaces.format(dMont hly));
}
}
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\tTh
System.out.println("\t\tTh
System.out.println("\t\tTh
System.out.println("\t\tTh
}
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
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 !!
:)
Cheers
Cheers