public class Loan {
   private double Rate; //annualInterestRate;
   private double Years; // int numberOfYears;
   private double Amount; //loanAmount
   private double Monthly;
   private java.util.Date loanDate;
   
   /** Default constructor */
   // Actually, I'm not going to allow a default constructor.
   // Give it all to me! -1 for the value we need to calculate.
   public Loan(double theRate, double theYears, double theAmount, double theMonthly) {
      loanDate = new java.util.Date(); // initialize
      
      // Rate is entered as a whole number, but processed as a decimal
      if (theRate >= 0)
         Rate = theRate / 100;
      
      Years = (double)(int)theYears; // only accepting the int portion
      Amount = theAmount;
      Monthly = theMonthly;
      
      if (Rate < 0) { // rate *can* be 0
         Rate = 999;
      }
      else if (Years <= 0) { // years can't be 0
         Years = 999;
      }
      else if (Amount <= 0) { // amount can't be 0
         Amount = 999;
      }
      else if (Monthly <= 0) { // monthly can't be 0
         // From the book, ch 10, adapted for clarity
         double mRate = Rate / 12;
         double numR = Amount * mRate;
         // Note: if mRate >= 0 and Years > 0, demR can't be 0 (no div/0)
         double demR = 1 / Math.pow(1 + mRate, Years * 12);
         demR = 1 - demR;
         Monthly = numR / demR;
      }
      


   }
   
   public double getRate() {
      // Returns in percentage, so multiply our internal
      return Rate * 100;
   }
   public double getYears() {
      return Years;
   }
   public double getAmount() {
      return Amount;
   }
   public double getMonthly() {
      return Monthly;
   }

} // end class Loan
@@ -590,35 +590,8 @@
 mal%0A
-      if (theRate %3E= 0)%0A   
     
@@ -692,16 +692,52 @@
 portion%0A
+      int Months = (int)Years * 12;%0A
       Am
@@ -799,223 +799,1093 @@
     
-if (Rate %3C 0) %7B // rate *can* be 0%0A         Rate = 999;%0A      %7D%0A      else if (Years %3C= 0) %7B // years can't be 0%0A         Years = 999;%0A      %7D%0A      else if (Amount %3C= 0) %7B // amount can't be 0%0A         Amount = 999
+// Formulas from: http://www.had2know.com/finance/mortgage-calculator-solver-4-variables.html%0A         // M = Monthly%0A         // P = principal Amount%0A         // N = Months%0A         // R = Rate%0A      if (Rate %3C 0) %7B // rate *can* be 0%0A         // %22Approximation Formula%22, doesn't require calculus!%0A         // R = (72/N)sqrt%5BMN/(3P) - 1/12%5D - 36/N%0A         double inSqr = (Monthly * Months) / (3.0 * Amount);%0A         inSqr -= 1.0/12.0;%0A         inSqr = Math.sqrt(inSqr);%0A         Rate = ((72.0/Months) * inSqr) - (36.0/Months);%0A      %7D%0A      else if (Years %3C= 0) %7B // years can't be 0%0A         // a/b, where%0A         // a = Log(M) - Log(M - PR/12)%0A         // b = Log(1 + R/12)%0A         // (any non-wooden log is ok)%0A         Years = 999;%0A      %7D%0A      else if (Amount %3C= 0) %7B // amount can't be 0%0A         // a/b, where%0A         // a = M%5B(1+R/12)%5EN - 1%5D%0A         // b = (R/12)(1+R/12)%5EN%0A         double toTheN = Math.pow(1 + (Rate/12.0), Months);%0A         double theTop = Monthly * (toTheN - 1.0);%0A         double theBottom = (Rate/12) * toTheN;%0A         Amount = theTop / theBottom
 ;%0A  
@@ -2192,26 +2192,22 @@
  mRate, 
-Years * 12
+Months
 );%0A     

Add 2 more calculators