I'm working on using a for-loop to create a table of values for a loan with payments over the course of a year. My code compiles and runs, and my output is fine, but I cannot get me numbers right in my output table.
I'm doing a $5,000 loan @ 12% APR. I think I should set my variables to their initial values before the loop, and then manipulate them mathematically within the loop.
Am I on the right track here?
Here is the code I have so far:
// Loan Calculator @Author Adam Long
// calculates a $5,000 loan at 12% APR
public class Asgn4a {
public static void main(
String[] args ) {
System.out.println( "Payment Interest Principal Balance Total Int ");
System.out.println( "=================================================");
double loan = 5000.00;
double interestRate = .01;
double interest = loan * interestRate;
double principal = (loan * 1.01) - interest;
double payment = principal + (interestRate * loan);
double balance = loan - principal;
for ( int count = 1; count <= 12; count++ ) {
interest = balance * interestRate;
principal = loan - balance;
balance -= principal;
double totalInt = interest * count;
System.out.printf( "%3d %9.2f %9.2f %9.2f %9.2f %9.2f\n",
count, interest, principal, balance, totalInt, payment);
}
}
}
[ October 21, 2007: Message edited by: Adam Long ]