import java.awt.*; import java.lang.*; import java.util.*; import java.io.*; import corejava.*; import java.net.*; import java.applet.*; // A class that create a buffer for a function. The object will be used for holding graph data // public class Graph { double xminimum=Double.POSITIVE_INFINITY; double xmaximum=Double.NEGATIVE_INFINITY; double yminimum=Double.POSITIVE_INFINITY; double ymaximum=Double.NEGATIVE_INFINITY; double NOTDEFINED = 0.0/0.0; /** * The total number of points. */ public int npoints = 0; /** * The array of x coordinates. */ public double xpoints[] = new double[1000]; /** * The array of y coordinates. */ public double ypoints[] = new double[1000]; // constructor // public Graph() { for (int i = 0; i<1000; i++) { ypoints[i]=0.0; xpoints[i]=0.0; } } // copy constructor : in = another Graph object. this function returns a duplicate of in // public Graph(Graph in) { //Graph(); for ( int i=0;i < in.numPoints();i++) this.addPoint( in.X(i), in.Y(i)); } // insert a point : x= value of x , y= value of y // void addPoint(double x, double y) { if (npoints == xpoints.length) { double tmp[]; tmp = new double[npoints * 2]; System.arraycopy(xpoints, 0, tmp, 0, npoints); xpoints = tmp; tmp = new double[npoints * 2]; System.arraycopy(ypoints, 0, tmp, 0, npoints); ypoints = tmp; } xpoints[npoints] = x; ypoints[npoints] = y; npoints++; xminimum = Math.min(xminimum, x); xmaximum = Math.max(xmaximum, x); if (Math.abs(y) < Double.POSITIVE_INFINITY) { yminimum = Math.min(yminimum, y); ymaximum = Math.max(ymaximum, y); } } // returns a absolute value of this object // Graph abs() { Graph out = new Graph(); for (int i=0; i< npoints;i++) { out.addPoint(xpoints[i], Math.abs(ypoints[i])); } return out; } // returns values + T // // T is a constant // Graph add(double T) { Graph out = new Graph(); for (int i=0; i