/*****************************************************************
** CapacitorCharging - demonstrated Math.exp() method
**
** This program calculates the charging voltage across a capactor
** (C), given a series resistor (R) and an applied voltage (Vi).
** The charging voltage is given by the formula
**
**    V = Vi * (1 - e^(-t/RC))
**
** A sample dialogue with this program follows:
**
**    C:\>java CapacitorCharging
**    Capacitance (uF): 1.5
**    Resistance (k): 33
**    Applied voltage (v): 12
**
**    t (us)   voltage (v)
**    -----------------------------
**    1        2.4242179371114503E-4
**    10       0.0024239975677593506
**    100      0.024217953426646677
**    1000     0.23999191951895327
**    10000    2.1950589463112236
**    100000   10.408455975563244
**    1000000  11.999999979790509
**
** (c) Scott MacKenzie, 2000                             
******************************************************************/
import java.io.*;

public class CapacitorCharging
{
   public static void main(String[] args) throws IOException
   {
      BufferedReader stdin =
         new BufferedReader(new InputStreamReader(System.in), 1);

      // Input value of capacitor (micro Farads)
      System.out.print("Capacitance (uF): ");
      double c = Double.parseDouble(stdin.readLine()) * 1000000;

      // Input value of resistor (in kilo Ohms)
      System.out.print("Resistance (k): ");
      double r = Double.parseDouble(stdin.readLine()) / 1000;

      // Input value of input voltage (v)
      System.out.print("Applied voltage (v): ");
      double vi = Double.parseDouble(stdin.readLine());

      System.out.println("\nt (us)\tvoltage (v)");
      System.out.println("-----------------------------");
      for (int t = 1; t <= 1000000; t *= 10)
      {
         double v = vi * (1 - Math.exp( -t / (r * c)));
         System.out.println(t + "\t" + v);
      }
   }
}

