/*
BOTH ABSTRACT AND FINAL CLASSES DON'T EXIST. BUT, YOU CAN DO IT:
WHEN TO DO IT: WHEN ALL ATTRIBUTES AND METHODS ARE STATIC.
Math is public final class Math
And all its attributes and methods are static.
And, in order to don't let anyone instantiate
this class has a private constructor:
http://www.docjar.com/html/api/java/lang/Math.java.html
 */
public final class MyMath {
    public static final double E = 2.7182818284590452354;
    public static final double PI = 3.14159265358979323846;
    private static final int N = 20; // Constante privada
    private MyMath() {
    } // Don't let anyone instantiate this class.
    // Los proximos metodos son funciones C con "public static" delante
    // http://people.ac.upc.edu/guerrero/fo2015/t4_sin_cos.c
    public static double factorial(int n) {
        int i;
        double f;
        for (f = 1, i = 2; i <= n; i++) {
            f *= i;
        }
        return f;
    }
    public static double potencia(double b, int e) {
        int i;
        double p;
        for (p = 1, i = 1; i <= e; i++) {
            p *= b;
        }
        return p;
    }
    public static double e_elevat_x(int x) {
        int i;
        double sum;
        for (sum = 0, i = 0; i <= N; i++) {
            sum += potencia(x, i) / factorial(i);
        }
        return sum;
    }
    public static double cos(double x) {
        int i;
        double sum;
        for (sum = 0, i = 0; i <= N; i++) {
            sum += potencia(x, 2 * i) / factorial(2 * i)
                    * potencia(-1, i);
        }
        return sum;
    }
    public static double sin(double x) {
        int i;
        double sum;
        for (sum = 0, i = 0; i <= N; i++) {
            sum += potencia(x, 2 * i + 1)
                    / factorial(2 * i + 1)
                    * potencia(-1, i);
        }
        return sum;
    }
    // main() para testear
    // Aqui no hace falta poner MyMath.potencia() o MyMath.E
    public static void main(String[] args) {
        int x = 10;
        System.out.println("e^" + x + " = (aprox) " + e_elevat_x(x));
        System.out.println("e^" + x + " = " + potencia(E, x));
        System.out.println("sin(PI) = " + sin(PI));
        System.out.println("cos(PI) = " + cos(PI));
    }
}
