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

class generator 
 {
  String program;
  String filename;
  String TYPE;
  //Available types
  PrintStream fout;
  PrintStream ferr;
  boolean created=false;
  
  public generator(String filename,String program,String TYPE)
  { this.program=program;
    this.filename=filename;
    if(TYPE.equals("f_x") || 
       TYPE.equals("fi_x") || 
       TYPE.equals("fi_xi")||
       TYPE.equals("general"))
       {this.TYPE=TYPE;}
    else
       {this.TYPE="general";}
    try {
    fout=new PrintStream(new FileOutputStream("print.txt"));
    ferr=new PrintStream(new FileOutputStream("error.txt"));
    }catch(FileNotFoundException e1) {System.err.println("file is not found");} 
  }
    
  public void addprogram(String program)
  {this.program=program;}
  public void addfilename(String filename)
  {this.filename=filename;}
  public void addTYPE(String TYPE)
  {    if(TYPE.equals("f_x") || 
       TYPE.equals("fi_x") || 
       TYPE.equals("fi_xi")||
       TYPE.equals("general"))
       {this.TYPE=TYPE;}
    else
       {this.TYPE="general";}
  }
  
  public String toString()
  {return program;}
  
  public generator()
  {program="x*x-4.0";
   filename="f2D";
   TYPE="f_x";
  }
  
 public  String create() 
 {String name=filename+".java";
 String s="";
 try {PrintWriter ffout=new PrintWriter(new BufferedWriter(new FileWriter(isim))); 
 s+="class "+filename+" extends f_x\n";
 s+=" {\n";
 s+=" public double func (double x)\n";
 s+="{ double y="+program+";\n";
 s+=" return y;\n";
 s+="}\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{
 JavaCompiler javac = ToolProvider.getSystemJavaCompiler();
 int rc = javac.run(null,null,null,isim);}
 catch(NullPointerException e1) {System.err.println("NULL POINTER");} 
 return program;
}

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