@@ -40,11 +40,11 @@ public boolean isImaginary() {
40
40
}
41
41
42
42
public boolean equals (double real , double imag ) {
43
- return (thix .real == real && this .imag = imag );
43
+ return (this .real == real && this .imag = = imag );
44
44
}
45
45
46
46
public boolean equals (MyComplex another ) {
47
- return (thix . real == another .getReal () && this . imag = another .getImag ());
47
+ return (real == another .getReal () && imag = = another .getImag ());
48
48
}
49
49
50
50
public double magnitude () {
@@ -56,7 +56,7 @@ public double argumentInRadians() {
56
56
}
57
57
58
58
public int argumentInDegrees () {
59
-
59
+ return 0 ;
60
60
}
61
61
62
62
public MyComplex conjugate () {
@@ -73,18 +73,23 @@ public MyComplex substract(MyComplex another) {
73
73
74
74
public MyComplex multiplyWith (MyComplex another ) {
75
75
// (ac - bd) + (ad + bc)i
76
- return new MyComplex (
77
- real *another .getReal () - imag *another .getImag ()
78
- , real *another .getImag () + imag *another .getReal ()
79
- );
76
+ real = real *another .getReal () - imag *another .getImag ();
77
+ imag = real *another .getImag () + imag *another .getReal ();
78
+ return this ;
80
79
}
81
80
82
81
public MyComplex divideBy (MyComplex another ) {
83
82
// [(a + bi) * (c – di)] / (c2 + d2)
84
-
83
+ MyComplex tmp = multiplyWith (another .conjugate ());
84
+ double delimiter = another .getReal ()*another .getReal () + another .getImag ()*another .getImag ();
85
+ if (delimiter != 0 ) {
86
+ real = tmp .getReal () / delimiter ;
87
+ imag = tmp .getImag () / delimiter ;
88
+ }
89
+ return this ;
85
90
}
86
91
87
92
public String toString () {
88
- return "(" +real " + " + imag +"i)" ;
93
+ return "(" +real + " + " + imag +"i)" ;
89
94
}
90
95
}
0 commit comments