//======================================================
// Calculate the monthly payment amount for a mortgage
//======================================================
public class loanCalc
{
    /**
     * main method
     */

    public static void main (String[ ] args)
    {        
        double principle;               //the amount of principle
        double interest;                //the interest. Example .05
        int    months;                  //number of months
        
        try {
            principle = Double.parseDouble(args[0]);    //if no principle, use 100000
        }
        catch (Exception e) {
            principle = 100000;
        }

        try {
            interest = Double.parseDouble(args[1]);     //if no interest, use .04
        }
        catch (Exception e) {
            interest = .04;
        }

        try {
            months = Integer.parseInt(args[2]);         //if no months, use 180 (15 yrs)
        }
        catch (Exception e) {
            months = 180;
        }

        double amt =  loanCalc(principle, interest, months);
        System.out.printf("%.2f \n", amt);  
    }


    /**
     * A mortgage calculator method     
     */

    static double loanCalc(double principle, double interest, int mth)
    {
        double amount, mthInt, factor;

        mthInt = interest / 12;
        factor = Math.pow((1+mthInt),mth);
        amount = principle * (mthInt*factor) / (factor-1);

        return (amount);                         
    }
}