Skip to content

Commit f37d6a8

Browse files
authored
Remove unused multiply & divide methods from Complex Number(#2852)
This is because we haven't implemented the tests for multiplying or dividing a complex number with a real number (according to comments in tests.toml).
1 parent c0f9020 commit f37d6a8

File tree

2 files changed

+5
-19
lines changed

2 files changed

+5
-19
lines changed

exercises/practice/complex-numbers/.meta/src/reference/java/ComplexNumber.java

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
final class ComplexNumber {
22

33
private final double real;
4-
54
private final double imaginary;
65

76
ComplexNumber(double real, double imaginary) {
@@ -32,7 +31,10 @@ ComplexNumber subtract(ComplexNumber other) {
3231
}
3332

3433
ComplexNumber divide(ComplexNumber other) {
35-
return this.multiply(other.conjugate()).divide(Math.pow(other.abs(), 2));
34+
double divisor = Math.pow(other.real, 2) + Math.pow(other.imaginary, 2);
35+
return new ComplexNumber(
36+
(real * other.real + imaginary * other.imaginary) / divisor,
37+
(imaginary * other.real - real * other.imaginary) / divisor);
3638
}
3739

3840
double abs() {
@@ -44,14 +46,7 @@ ComplexNumber conjugate() {
4446
}
4547

4648
ComplexNumber exponentialOf() {
47-
return new ComplexNumber(Math.cos(imaginary), Math.sin(imaginary)).multiply(Math.exp(real));
49+
return new ComplexNumber(Math.exp(real) * Math.cos(imaginary), Math.exp(real) * Math.sin(imaginary));
4850
}
4951

50-
private ComplexNumber divide(double factor) {
51-
return new ComplexNumber(real / factor, imaginary / factor);
52-
}
53-
54-
private ComplexNumber multiply(double factor) {
55-
return new ComplexNumber(factor * real, factor * imaginary);
56-
}
5752
}

exercises/practice/complex-numbers/src/main/java/ComplexNumber.java

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -28,24 +28,15 @@ ComplexNumber multiply(ComplexNumber other) {
2828
throw new UnsupportedOperationException("Delete this statement and write your own implementation.");
2929
}
3030

31-
ComplexNumber multiply(double factor) {
32-
throw new UnsupportedOperationException("Delete this statement and write your own implementation.");
33-
}
34-
3531
ComplexNumber divide(ComplexNumber other) {
3632
throw new UnsupportedOperationException("Delete this statement and write your own implementation.");
3733
}
3834

39-
ComplexNumber divide(double divisor) {
40-
throw new UnsupportedOperationException("Delete this statement and write your own implementation.");
41-
}
42-
4335
ComplexNumber conjugate() {
4436
throw new UnsupportedOperationException("Delete this statement and write your own implementation.");
4537
}
4638

4739
ComplexNumber exponentialOf() {
4840
throw new UnsupportedOperationException("Delete this statement and write your own implementation.");
4941
}
50-
5142
}

0 commit comments

Comments
 (0)