package quadratischeFunktionen;

import java.awt.geom.Point2D;

/**
 * @author Thomas Kirz, Sebastian Vogt
 * @version 1.0 22.12.2015
 */
public class QuadraticFunction {

    // Test

    //Suggestion for x-values:
    //
    //private int xquantity;                          (result of user input)
    //private double[] fx = new double[xquantity];
    //private double xstep                            (result of user input)
    //privte double xstart                            (result of user input)
    //private double x = xstart
    //for(int i = 0; i <= xquantity; i++){
    //   fx[i] =  a * (Math.pow(x, 2)) + b * x + c    (the values of the array fx are the program's output)
    //   x = x + xstep
    //}


    /**
     * Parameters of the function (abc for ax² + bx + c and ade for a(x + d)² + e
     */
    private double a, b, c, d, e;

    /**
     * The vertex of the function
     */
    Point2D.Double vertex;

    /**
     * * Initializes a function with a, b and c and generates d, e and the vertex
     *
     * @throws IllegalArgumentException if a is zero
     */
    public QuadraticFunction(double a, double b, double c) throws IllegalArgumentException {
        if (a == 0) {
            throw new IllegalArgumentException("a must not be 0!");
        }
        this.a = a;
        this.b = b;
        this.c = c;
        generateVertex();
    }

    /**
     * @return the parameter a of the function
     */
    public double getA() {
        return a;
    }

    /**
     * @return the parameter b of the function
     */
    public double getB() {
        return b;
    }

    /**
     * @return the parameter c of the function
     */
    public double getC() {
        return c;
    }

    /**
     * @return the parameter d of the function
     */
    public double getD() {
        return d;
    }

    /**
     * @return the parameter e of the function
     */
    public double getE() {
        return e;
    }

    /**
     * Calculates y of the function for a given x
     *
     * @return y
     */
    public double getImageOf(double x) {
        return a * x * x + b * x + c;
    }

    /**
     * Gets the vertex of the function as a Point2D
     *
     * @return the vertex
     */
    public Point2D.Double getVertex() {
        return vertex;
    }

    /**
     * Generates the parameters d and e of the function f(x) = a(x + d)² + e
     * Used in constructor QuadraticFunction(double a, double b, double c)
     */
    private void generateVertex() {
        d =  b / (2 * a);
        e = (4 * a * c - b * b) / (4 * a);

        vertex = new Point2D.Double(-d, e);
    }

    /**
     * Generates a string of the function like ax²+ bx + c
     *
     * @return the string
     */
    public String toNormalString() {
        String part1, part2, part3;

        part1 = a + "x²";

        if (b > 0) {
            part2 = " + " + b + "x";
        } else if (b < 0) {
            part2 = " - " + -b + "x";
        } else {
            part2 = "";
        }

        if (c > 0) {
            part3 = " + " + c;
        } else if (c < 0) {
            part3 = " - " + -c;
        } else {
            part3 = "";
        }

        return part1 + part2 + part3;
    }

    /**
     * Generates a string of the function like a(x + d)²+ e
     * @return the string
     */
    public String toVertexString() {
        String part1, part2;
        if (d > 0) {
            part1 = a + "(x + " + d + ")²";
        } else if (d < 0) {
            part1 = a + "(x - " + -d + ")²";
        } else {
            part1 = a + "x²";
        }

        if (e > 0) {
            part2 = " + " + e;
        } else if (e < 0) {
            part2 = " - " + -e;
        } else {
            part2 = "";
        }

        return part1 + part2;
    }
}

@@ -55,16 +55,70 @@
 Point2D;
+%0Aimport java.util.ArrayList;%0Aimport java.util.HashMap;
 %0A%0A/**%0A *
@@ -2677,32 +2677,999 @@
 %0A    /**%0A     * 
+This method returns all images of a function for an ArrayList%0A     * @param list the ArrayList containing Doubles to be get an image%0A     * @return the HashMap with x as key and y as value%0A     */%0A    public HashMap%3CDouble, Double%3E getImagesOf(ArrayList%3CDouble%3E list) %7B%0A        HashMap%3CDouble, Double%3E images = new HashMap%3C%3E();%0A        list.forEach(x -%3E images.put(x, getImageOf(x)));%0A        return images;%0A    %7D%0A%0A    /**%0A     * This method returns all images of a function with x starting with start, ending with end and%0A     *%0A     * @param start%0A     * @param end%0A     * @param step%0A     * @return%0A     * @throws IllegalArgumentException%0A     */%0A    public HashMap%3CDouble, Double%3E getImagesOf(double start, double end, double step) throws IllegalArgumentException %7B%0A        ArrayList%3CDouble%3E list = new ArrayList%3C%3E();%0A        for (double i = start; i %3C= end; i += step) %7B%0A            list.add(i);%0A        %7D%0A        return getImagesOf(list);%0A    %7D%0A%0A    /**%0A     * 
 Generates a stri
@@ -3703,23 +3703,16 @@
 + bx + c
-%0A     *
 %0A     * 

Add methods that return HashMaps with function images