public class FixedPoint {
    public double tolerance = 0.00001;

    private boolean isCloseEnough(double x,
                                  double y) {
        return Math.abs(x - y) < tolerance;
    }

    public double fixedPoint(DoubleFun f,
                             double guess) {
        double fval = f.value(guess);
        while (!isCloseEnough(fval, guess)) {
            guess = fval;
            fval = f.value(guess);
        }
        return fval;
    }

    public static void main(String argv[]) {
        System.out.println("fixed point of cosine is "
              + new FixedPoint()
                 . fixedPoint(new Cosine(), 1.0));
    }
}
