home *** CD-ROM | disk | FTP | other *** search
/ io Programmo 14 / IOPROG_14.ISO / soft / sdkjava / sdkjava.exe / SDKJava.cab / Samples / AFC / LoanCalc / Src / LCParams.java < prev    next >
Encoding:
Java Source  |  1998-03-05  |  1.6 KB  |  75 lines

  1. //
  2. // (c) 1998 Microsoft Corporation.  All rights reserved.
  3. //
  4.  
  5. public class LCParams implements LCConsts
  6. {
  7.     public long pv;
  8.     public int i, len, hz_idx, n, pmnt;
  9.     public boolean years;
  10.     public double ip;
  11.  
  12.     public LCParams(LCParams lp)
  13.     {
  14.         this(lp.pv, lp.i, lp.len, lp.years, lp.hz_idx, lp.pmnt);
  15.     }
  16.  
  17.     public LCParams(long pv, int i, int len, boolean years, int hz_idx, int pmnt)
  18.     {
  19.         this.pv = pv; this.i = i; this.len = len; 
  20.         this.years = years; this.hz_idx = hz_idx; this.pmnt = pmnt;
  21.  
  22.         n = len*FREQ_FACTOR[hz_idx];
  23.         if ( !years )
  24.             n /= 12;
  25.  
  26.         ip = i/(FREQ_FACTOR[hz_idx]*800.0);
  27.     }
  28.  
  29.     // Calculate parameter that was = 0
  30.     public boolean calc(int what)
  31.     {
  32.         boolean setwiz = false;
  33.  
  34.         switch ( what ) {
  35.         case BL_PV:    pv = calcPV(); break;
  36.         // need to recalculate pmnt after calculating number of periods since n
  37.         //  will be rounded down to the nearest int. May also need to reset text in Wizard
  38.         case BL_LEN: n = calcN(); setwiz = true; // Fall through
  39.         case BL_PMNT: pmnt = calcPmnt(); break;
  40.         }
  41.         return setwiz;
  42.     }
  43.  
  44.     public int calcPmnt()
  45.     {
  46.         if ( n == 0 ) n = 1;
  47.         double factor = Math.pow(1.0 + ip, n);
  48.         return (int)(((factor*ip*pv)/(factor - 1.0))*100.0);
  49.     }
  50.  
  51.     public long calcPV()
  52.     {
  53.         if ( n == 0 ) n = 1;
  54.         double factor = Math.pow(1.0 + ip, n);
  55.         return (long)(((factor - 1.0)*(pmnt/100.0))/(factor*ip));
  56.     }
  57.  
  58.     public int calcN()
  59.     {
  60.         double a = pmnt/100.0;
  61.         int n = (int)(Math.log(a/(a-(pv*ip)))/Math.log(1.0+ip)); 
  62.         if ( n == 0 )
  63.             n = 1;
  64.         len = n*(12/FREQ_FACTOR[hz_idx]);
  65.         if ( (len % 12) == 0 ) {
  66.             len /= 12;
  67.             years = true;
  68.         }
  69.         else
  70.             years = false;
  71.  
  72.         return n;
  73.     }
  74. }
  75.