Auf Thema antworten

[CODE=java]public class FunktionTest {


    public interface Funktion<T extends Number, K extends Number> {


        T calculate(K x);


    }


    public static Funktion<Double, Double> makeChain(final Funktion<Double, Double>[] funs) {


        return x -> {

            for (Funktion<Double, Double> f : funs) {

                x = f.calculate(x);

            }

            return x;

        };


    }


    public static void main(String[] args) {

        // b

        Funktion<Double, Double> id = (Double x) -> x;

        Double a = id.calculate(10.0);

        System.out.println(a);


        Funktion<Double, Double> inverse = (Double x) -> x * (-1);

        Double a1 = inverse.calculate(-5.3);

        System.out.println(a1);


        Funktion<Double, Double> timesTen = (Double y) -> (y * 10);

        Double a2 = timesTen.calculate(a1);

        System.out.println(a2);


        Funktion<Double, Double> divideByPi = (Double y) -> (y / 3.14);

        Double a3 = divideByPi.calculate(a2);

        System.out.println(a3);


        // c


        Funktion<Double, Double> round = (Double x) -> x;

        Double b = round.calculate(a3);

        System.out.println(Math.round(b));


        // d

       

        Funktion<Double, Double> chain = makeChain(new Funktion[] { inverse, id,

                timesTen,  divideByPi });

       

        Double g = chain.calculate(5.5);

        System.out.println(Math.round(g));


    }

}[/CODE]


Ich danke dir für den Hinweis. jetzt funktioniert fabelhaft....



Oben