public class EuropeanOptPrice
{

  // Declaration of the Native (C) function
  private native int s30aac(char calput, int m, int n, double[] x, double s,
                            double[] t, double sigma, double r, double q, 
                            double[] p);

  static
    {
      // The runtime system executes a class's static
      // initializer when it loads the class.
      System.loadLibrary("nagCJavaInterface");
    }

  // The main program
  public static void main(String[] args)
    {
      double x[], t[], p[];
      double s, sigma, r, q;
      int i, j, m, n, retCode;
      char calput;

      // Create an object of class EuropeanOptPrice
      EuropeanOptPrice price = new EuropeanOptPrice();

      calput = 'C';
      s = 55.0;
      sigma = 0.3;
      r = 0.1;
      q = 0.0;
      m = 3;
      n = 2;

      p = new double[m*n];
      x = new double[m];
      t = new double[n];

      for (i = 0; i < m*n; i++)
        p[i] = 0.0;

      x[0] = 58.0;
      x[1] = 60.0;
      x[2] = 62.0;

      t[0] = 0.7;
      t[1] = 0.8;

      System.out.println();
      System.out.println("Call of NAG Black-Scholes-Merton option pricing routine s30aac");
      System.out.println();

      // Call method s30aac of object price
      retCode = price.s30aac(calput, m, n, x, s, t, sigma, r, q, p);

      System.out.print("Return code from s30aac = ");
      System.out.println(retCode);
      System.out.println();

      if (retCode == 0)
        {
          // Print the input values
          System.out.println("European Call:");
          System.out.println("Spot " + s);
          System.out.println("Volatility " + sigma);
          System.out.println("Rate " + r);
          System.out.println("Dividend " + q);
          System.out.println();

          // Print the solution
          System.out.println(" Strike      Expiry     Option Price");
          for (i = 0; i < m; i++)
            {
              for (j = 0; j < n; j++)
                System.out.format("%8.4f   %8.4f   %8.4f%n",x[i],t[j],p[i*n + j]);
            }
          System.out.println();
        }
    }
}
