class Complex{

    // main Methode zum testen der Klasse
    static public void main(String argv[]) {
        Complex c1 = new Complex( -5 , 10 );
        Complex c2 = new Complex( 3 , 4 );

        Float f1 = new Float( 0 );

        c1.div( c2 );

        System.out.println( c1.real + " + " + c1.imag + "i" );
    }

    // Konstruktoren
    public Complex() {
        super();
    }
    public Complex( float real, float imag ) {
        super();
        this.real = real;
        this.imag = imag;
    }

    // Methoden zum rechnen
    public Complex add( Complex value ) {
        real = real + value.real;
        imag = imag + value.imag;
        return this;
    }
    public Complex sub( Complex value ) {
        real = real - value.real;
        imag = imag - value.imag;
        return this;
    }
    public Complex mul( Complex value ) {
        float old_real = real;
        real = (real * value.real) - (imag * value.imag);
        imag = (old_real * value.imag) + (imag * value.real);
        return this;
    }
    public Complex div( Complex value ) {
        Complex value_inv = new Complex();
        value_inv.real = value.real/(value.real*value.real+value.imag*value.imag);
        value_inv.imag = -value.imag/(value.real*value.real+value.imag*value.imag);

        mul( value_inv );

        return this;
    }
    public float abs( Complex value ) {
        double abs = java.lang.Math.sqrt ((value.real * value.real) + (value.imag * value.imag));
        return (float) abs;
    }

    public float real;
    public float imag;
}

