/Users/lyon/j4p/src/bookExamples/ch05ControlStructs/LoanPayment.java

1    /* 
2     * @author Douglas A. Lyon 
3     * @version  Nov 1, 2002.7:03:49 AM 
4     */ 
5    package bookExamples.ch05ControlStructs; 
6     
7     
8    public class LoanPayment { 
9     
10       public static void main(String args[]) { 
11           double apr = 0.06; 
12           double principle = 15000; 
13           double numberOfMonths = 48; 
14           double monthlyInterestRate = apr / 12; 
15           double monthlyPayment = 
16                   principle * (monthlyInterestRate 
17                   / (1 - Math.pow(1 + monthlyInterestRate, -numberOfMonths))); 
18           double Q = 1; 
19    
20           for (int x = 1; Q > 0; x++) { 
21               double H = principle * monthlyInterestRate; 
22               double C = monthlyPayment - H; 
23               Q = principle - C; 
24               principle = Q; 
25           } 
26    
27           System.out.println( 
28                   "The amount of your monthly payment is: " + monthlyPayment); 
29    
30       } 
31   }