public class ComplexGet { private double re, im; public ComplexGet(double reëel, double imag) { re = reëel; im = imag; } public double real() { return re; } public double imaginair() { return im; } public void optellen(ComplexGet y) { re = re + y.real(); im = im + y.imaginair(); } public void vermenigvuldigen(ComplexGet y) { re = ((re * y.real()) - (im * y.imaginair())); im = ((re * y.imaginair()) + (im * y.real())); } public void inverteren(ComplexGet x) { re = (x.real() / (x.real() * x.real()) + (x.imaginair() * x.imaginair())); im = (x.imaginair() / (x.real() * x.real()) + (x.imaginair() * x.imaginair())); } }
public class main { public static void main(String[] args) { ComplexGet getal1 = new ComplexGet(1.0, 2.0); ComplexGet getal2 = new ComplexGet(3.0, 4.0); ComplexGet temp = getal1; ComplexGet temp2= getal1; ComplexGet temp3= getal1; temp.optellen(getal2); System.out.printf("Som = %.1f + %.1fi"+"\n", temp.real(), temp.imaginair()); temp2.vermenigvuldigen(getal2); System.out.printf("Vermenigvuldiging = %.1f + %.1fi"+"\n", temp2.real(), temp2.imaginair()); temp3.inverteren(getal1); System.out.printf("Inverteren = %.1f + %.1fi", temp3.real(), temp3.imaginair()); } }
After the first "optellen" that means counting up the 2 numbers are counted up works fine. But then for "vermenigvuldigen", multiplication it takes the complex number of the som and getal2. And it should be getal1 and getal2 not the numbers from the som. Any help?