roscoo
asked on
Mortgage Armortization Calculator
Ok I am trying to get this code to work. I want an armotized morgage calculator the shows the date, monthly interest, montly payment, and principal for 360 months. When I run this code it just gives me the same number. I am confused. I think the println is incorrect but not sure what to do. I have seen another question posted but the code was too complicated for me to understand. I just want to keep it very simple.
Thanks
import java.lang.Math; // Math library
import java.text.NumberFormat; // Number formatting
import java.io.*;
public class MortgCalc
{
public static void main (String[] args)
{
/*setting variables*/
double principal = 200000;
double interest_rate = 5.75;
double term = 360;
double payment;
double MonthlyPerc;
double LoanAmt = principal;
double Monthly_principal;
double Monthly_interest;
/*formula*/
MonthlyPerc = (interest_rate /12 * .01); // converts interest rate into months
payment = principal * MonthlyPerc / (1 - Math.pow(1 + MonthlyPerc, -term));
/*Formats the payment*/
NumberFormat result_formatter;
result_formatter = NumberFormat.getCurrencyIn stance();
String result_output;
result_output = result_formatter.format(pa yment);
/*loop*/
for (int i=1; i < 361; i++)
{
Monthly_principal = (payment -(LoanAmt * MonthlyPerc));
Monthly_interest = (LoanAmt * MonthlyPerc);
/*Screen Display*/
System.out.println(Monthly _principal + Monthly_interest + payment-Monthly_principal) ;
}
}
}
Thanks
import java.lang.Math; // Math library
import java.text.NumberFormat; // Number formatting
import java.io.*;
public class MortgCalc
{
public static void main (String[] args)
{
/*setting variables*/
double principal = 200000;
double interest_rate = 5.75;
double term = 360;
double payment;
double MonthlyPerc;
double LoanAmt = principal;
double Monthly_principal;
double Monthly_interest;
/*formula*/
MonthlyPerc = (interest_rate /12 * .01); // converts interest rate into months
payment = principal * MonthlyPerc / (1 - Math.pow(1 + MonthlyPerc, -term));
/*Formats the payment*/
NumberFormat result_formatter;
result_formatter = NumberFormat.getCurrencyIn
String result_output;
result_output = result_formatter.format(pa
/*loop*/
for (int i=1; i < 361; i++)
{
Monthly_principal = (payment -(LoanAmt * MonthlyPerc));
Monthly_interest = (LoanAmt * MonthlyPerc);
/*Screen Display*/
System.out.println(Monthly
}
}
}
Do you want the LoanAmt to go down whenever a payment is made?
thats cause u don't update your vars
should be more like:
import java.lang.Math; // Math library
import java.text.NumberFormat; // Number formatting
import java.io.*;
public class MortgCalc
{
public static void main (String[] args)
{
/*setting variables*/
double principal = 200000;
double interest_rate = 5.75;
double term = 360;
double payment;
double MonthlyPerc;
double LoanAmt = principal;
double Monthly_principal;
double Monthly_interest;
/*formula*/
MonthlyPerc = (interest_rate /12 * .01); // converts interest rate into months
payment = principal * MonthlyPerc / (1 - Math.pow(1 + MonthlyPerc, -term));
/*Formats the payment*/
NumberFormat result_formatter;
result_formatter = NumberFormat.getCurrencyIn stance();
String result_output;
result_output = result_formatter.format(pa yment);
/*loop*/
Monthly_interest = (LoanAmt * MonthlyPerc);
for (int i=1; i < 361; i++)
{
Monthly_interest = LoanAmt * MonthlyPerc;
Monthly_principal = (payment - Monthly_interest);
LoanAmt -= Monthly_principal;
/*Screen Display*/
System.out.println(i+" "+Monthly_principal+" "+LoanAmt);
}
}
}
import java.lang.Math; // Math library
import java.text.NumberFormat; // Number formatting
import java.io.*;
public class MortgCalc
{
public static void main (String[] args)
{
/*setting variables*/
double principal = 200000;
double interest_rate = 5.75;
double term = 360;
double payment;
double MonthlyPerc;
double LoanAmt = principal;
double Monthly_principal;
double Monthly_interest;
/*formula*/
MonthlyPerc = (interest_rate /12 * .01); // converts interest rate into months
payment = principal * MonthlyPerc / (1 - Math.pow(1 + MonthlyPerc, -term));
/*Formats the payment*/
NumberFormat result_formatter;
result_formatter = NumberFormat.getCurrencyIn
String result_output;
result_output = result_formatter.format(pa
/*loop*/
Monthly_interest = (LoanAmt * MonthlyPerc);
for (int i=1; i < 361; i++)
{
Monthly_interest = LoanAmt * MonthlyPerc;
Monthly_principal = (payment - Monthly_interest);
LoanAmt -= Monthly_principal;
/*Screen Display*/
System.out.println(i+" "+Monthly_principal+" "+LoanAmt);
}
}
}
ASKER
Thanks the code worked great. I really appreciate it.
Is there a way to round the numbers and make it pause so that you are able to view sections at a time.
Thanks
Is there a way to round the numbers and make it pause so that you are able to view sections at a time.
Thanks
To round the numbers use the NumberFormat class to format them as required.
eg.
System.out.println(i+" "+result_formatter.format( Monthly_pr incipal)+" "+result_formatter.format( LoanAmt));
To pause use something like:
if (i%20==0) System.in.read();
eg.
System.out.println(i+" "+result_formatter.format(
To pause use something like:
if (i%20==0) System.in.read();
ASKER
Not sure where to put the pause statement. When I put it within the loop after the print statements I got an error "cannot find symbol" "variable i"
put it inside the loop
for (int i=1; i < 361; i++)
{
Monthly_interest = LoanAmt * MonthlyPerc;
Monthly_principal = (payment - Monthly_interest);
LoanAmt -= Monthly_principal;
/*Screen Display*/
System.out.println(i+" "+Monthly_principal+" "+LoanAmt);
if (i%20==0) System.in.read();
}
{
Monthly_interest = LoanAmt * MonthlyPerc;
Monthly_principal = (payment - Monthly_interest);
LoanAmt -= Monthly_principal;
/*Screen Display*/
System.out.println(i+" "+Monthly_principal+" "+LoanAmt);
if (i%20==0) System.in.read();
}
ASKER
Now I get an error stating that "unreported exceptions java.io.IOException; must be caught or declared to be thrown"
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.