Adam Long

Greenhorn
+ Follow
since Oct 21, 2007
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Adam Long

Thanks for the suggestions. I appreciate the help. I got it pretty much figured out.
16 years ago
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 ]
16 years ago