/**
 * 
 * Write a program that takes 2 command line arguments representing 
 * P: price in dollars
 * Y: number of years
 * I : interest rate
 * 
 * calculate the monthly payments that would need to be made in order to pay off
 * a loan of P dollars at I percent interest compounded monthly. 
 * 
 * Using the formula:
 * 
 *  
 *                               P r 
 *     payment =  -----------------        
 *                       1  - (1 + r)^(-n)
 *
 * where 
 * n = 12 * Y (number of months)
 * r = I / 12 / 100 (monthly interest rate)
 * 
 * Hints: 
 * - You will need to look in the Math class for an appropriate funtion to use
 * - Use the following in your code:
 *    String P = args[0];
 *    String Y = args[1];
 *    String I = args[2];
 * 
 * */

public class LoanPayments {
  public static void main(String[] args) { 
    double P = Double.parseDouble(args[0]);
    double Y = Double.parseDouble(args[1]);
    double I = Double.parseDouble(args[2]);
    
    double r = I / 12 / 100;    // monthly interest rate
    double n = 12 * Y;         // number of months
    
    double payment  = (P * r) / (1 - Math.pow(1+r, -n));
    double interest = payment * n - P;
    
    System.out.println("Monthly payments = " + payment);
    System.out.println("Total interest   = " + interest);
  }
  
}
 
