import java.io.*;
import javax.swing.*;
import javax.tools.*;
import java.util.*;
import java.lang.Math.*;
import java.lang.*;


class functiongenerator_fxi 
 {
  String fonksiyon[];
  String dosyaismi;
  String sinif;
  PrintStream fout;
  PrintStream ferr;

  public functiongenerator_fxi(String dosyaismi,String fonksiyon[])
  { this.fonksiyon=fonksiyon;
    this.dosyaismi=dosyaismi;
    try {
    fout=new PrintStream(new FileOutputStream("print.txt"));
    ferr=new PrintStream(new FileOutputStream("error.txt"));
    }catch(FileNotFoundException e1) {System.err.println("file can not be found");} 
  }
  
  public functiongenerator_fxi(String fonksiyon[])
  {this.fonksiyon=fonksiyon;
   dosyaismi="fxi";
  }
  
  public void addfunction(String fonksiyon[])
  {this.fonksiyon=fonksiyon;}
  
  public String toStrings()
  {return fonksiyon;}
  
  public String toString()
  { String s="";
    for(int i=0;i<fonksiyon.length;i++)
    {s+="f["+i+"] = "+fonksiyon[i]+" ";}	  
	  return s;
  }
  
  public functiongenerator_fixi()
  {  String fonksiyon[]={"x[0]*x[0]-4.0","x[1]*x[0]+4"};
   dosyaismi="fixi";
  }
  
 public  String createfunction() 
 {String isim=dosyaismi+".java";
 String s="";
 try {PrintWriter ffout=new PrintWriter(new BufferedWriter(new FileWriter(isim))); 
 s+="class "+dosyaismi+" extends fi_xi\n";
 s+=" {\n";
 s+=" public double[] func(double x[])\n";
 s+="{ double y[]=new double["+fonksiyon.length+"];\n";
for(int i=0;i<fonksiyon.length;i++) 
{s+=" y["+i+"]="+fonksiyon[i]+";\n";}
 s+=" return y;\n";
 s+="}}\n";
 sinif=s;
 ffout.println(s);
 //System.out.println(s);
 ffout.close();
 }
 catch(IOException e1) {System.err.println("girdi hatası.");} 
 catch(NumberFormatException e2){};
 try
 {//java derleyicisi
 JavaCompiler javac = ToolProvider.getSystemJavaCompiler();
 int rc = javac.run(null,null,null,isim);
 }
 catch(NullPointerException e1) {System.err.println("NULL POINTER");} 
 return toString();
}

 protected void finalize() throws Throwable
 {super.finalize();}
 }
