# Mortgage Calculator amortization

Ok experts!!! You have yet to let me down and this one has me confused. I have a mortgage calculator that calculates the interest rate for each payment based off a set APR and number of months. The mortgage amount is inputted by the user. The problem I am having is that now the APR is not calculating at all and it displays \$0.00. This is not correct....could someone please take a look at the code and let me know what I forgot to do. Thanks
Here is the code out of TextPad:
import java.io.*;
import java.text.DecimalFormat;

public class Conlys
{
public static void main (String[] args)throws IOException
{

//Declare Variables
//String - for user input
String Loan = "X" ;

//Int stores whole number value

int [] intAPR = {0, 2, 3};
int Termmonths;
int [] Years = {7, 15, 30};
int paymentNum = 1;
int Term = 0;

//Double - Store values with decimal places
double Principal = 0;
double MonthlyInt;
double Payment = 1;
double Division;
double InterestPd = 0;
double Balance = 0;
double [] APR = {5.35, 5.5, 5.75};
double NewMonthlyRate = 0;
double NewBalance = 0;
double MonthlyRate= 0;

DecimalFormat money = new DecimalFormat( "\$0.00");

//Print prompts and get input
System.out.println("\t\t\tDavid Conly's Mortgage Calculator");
System.out.println("\tPurpose:Calculate the monthly payment based on customer input.\n");

try //Validation for user input
{

System.out.print( "\n\tEnter mortgage amount-Whole amounts only, no commas or cents:");
Loan = dataIn.readLine (); // user input
Principal = Integer.parseInt(Loan); // converts string to integer

}

catch (NumberFormatException nfe)
{

System.out.println("Okay, this will be wrong. Follow directions next time." ); //response to incorrect format

}

if (Principal <= 0 || Principal >= 1000000)
{

System.out.print("\n\tLoan amount must be between 0 and 1000000. Please try again.");

}

//Calculations

//Term Months Calculation
Termmonths=Years[0]*12;

//Monthly Interest Calculation
MonthlyInt=APR[0]/(12*100);

//Division Calculation
Division= 1-(Math.pow (1+MonthlyInt,-Termmonths));

//Payment Calculation
Payment=Principal*(MonthlyInt/Division);

//Balance due after payment calculation
Balance = Principal - Payment;

//Interest paid this payment
InterestPd = Payment * APR[0]*.01;

//output line for APR percentage selected
System.out.print("\n\nThe first available APR is " + APR[0]+"%");

//output line for monthly pmt.
System.out.println("\nThe Monthly Payment is " + (money.format(Payment)));

//output line for term in years
System.out.print("The first available Term in years is " + Years[0]);

//output line for loan balance after pmt.
System.out.print("\nThe Loan Balance is " + (money.format(Balance)));

//output line for interest paid this pmt.
System.out.print("\nThe Interest Paid Is " + (money.format(InterestPd)));

while (paymentNum<Termmonths)
{

System.out.print("\n\tPress enter to see interest paid and balance\n\n");

System.out.println("\nNumber \t" + "Interest \t" + "Ending Balance");

for (int lineNumb=1;paymentNum<=Termmonths && lineNumb<=30;lineNumb++)
{

NewMonthlyRate = Balance*MonthlyRate;
Principal = Payment - NewMonthlyRate;
NewBalance = Balance - Principal;
Balance = NewBalance;
System.out.println(" " + paymentNum + "\t " +
money.format(NewMonthlyRate) + "\t\t " +      money.format(NewBalance));
paymentNum++;

}

}

//Calculations

//Term Months Calculation
Termmonths=Years[1]*12;

//Monthly Interest Calculation
MonthlyInt=APR[1]/(12*100);

//Division Calculation
Division= 1-(Math.pow (1+MonthlyInt,-Termmonths));

//Payment Calculation
Payment=Principal*(MonthlyInt/Division);

//Balance due after payment calculation
Balance = Principal - Payment;

//Interest paid this payment
InterestPd = Payment * APR[1]*.01;

//output line for APR percentage selected
System.out.print("\n\nThe second available APR is " + APR[1]+"%");

//output line for monthly pmt.
System.out.println("\nThe Monthly Payment is " + (money.format(Payment)));

//output line for term in years
System.out.print("The second available Term in years is " + Years[1]);

//output line for loan balance after pmt.
System.out.print("\nThe Loan Balance is " + (money.format(Balance)));

//output line for interest paid this pmt.
System.out.print("\nThe Interest Paid Is " + (money.format(InterestPd)));

while (paymentNum<Termmonths)
{

System.out.print("\n\tPress enter to see interest paid and balance\n\n");

System.out.println("\nNumber \t" + "Interest \t" + "Ending Balance");

for (int lineNumb=1;paymentNum<=Termmonths && lineNumb<=30;lineNumb++)
{

NewMonthlyRate = Balance*MonthlyRate;
Principal = Payment - NewMonthlyRate;
NewBalance = Balance - Principal;
Balance = NewBalance;
System.out.println(" " + paymentNum + "\t " +
money.format(NewMonthlyRate) + "\t\t " + money.format(NewBalance));
paymentNum++;

}

}

//Calculations

//Term Months Calculation
Termmonths=Years[2]*12;

//Monthly Interest Calculation
MonthlyInt=APR[2]/(12*100);

//Division Calculation
Division= 1-(Math.pow (1+MonthlyInt,-Termmonths));

//Payment Calculation
Payment=Principal*(MonthlyInt/Division);

//Balance due after payment calculation
Balance = Principal - Payment;

//Interest paid this payment
InterestPd = Payment * APR[2]*.01;

//output line for APR percentage selected
System.out.print("\n\nThe third available APR is " + APR[2]+"%");

//output line for monthly pmt.
System.out.println("\nThe Monthly Payment is " + (money.format(Payment)));

//output line for term in years
System.out.print("The third available Term in years is " + Years[2]);

//output line for loan balance after pmt.
System.out.print("\nThe Loan Balance is " + (money.format(Balance)));

//output line for interest paid this pmt.
System.out.print("\nThe Interest Paid Is " + (money.format(InterestPd)));

while (paymentNum<Termmonths)
{

System.out.print("\n\tPress enter to see interest paid and balance\n\n");

System.out.println("\nNumber \t" + "Interest \t" + "Ending Balance");

for (int lineNumb=1;paymentNum<=Termmonths && lineNumb<=30;lineNumb++)
{

NewMonthlyRate = Balance*MonthlyRate;
Principal = Payment - NewMonthlyRate;
NewBalance = Balance - Principal;
Balance = NewBalance;
System.out.println(" " + paymentNum + "\t " +
money.format(NewMonthlyRate) + "\t\t " + money.format(NewBalance));
paymentNum++;

}

}

}
}
###### Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Commented:
I tried your program, what I see is that NewMonthlyRate is always 0, otherwise it seems OK.
NewMonthlyRate is always 0 because MonthlyRate is initially set to 0 and never changed, and as NewMonthlyRate is set to Balance*MonthlyRate at lines 123, 187 and 250, it will always be 0 too.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Author Commented:
elfe69,
Ok, I see tht too but what or how should I change that? If I blank it out I still get the same thing.
0
Commented:
You should set MonthlyRate to the monthly interest rate either before your first loop (if the interest rate is fixed) or after the beginning of each loop (if the interest rate changes with the time)
0
###### It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Java

From novice to tech pro — start learning today.