This method is intended to divide a complex number (a real number plus an imaginary number) with another complex number. My assignment has certain formulas for certain scenarios, so I invoked an if statement.
Eclipse is telling me that the method needs to return a Complex class, which okay, I understand, but I'm confused.
One of the "scenarios" deals with both the real and imaginary parts of the Complex number equaling 0. The result is supposed to be "undefined" but I put "null" in. Maybe that's it?
I don't know. Please help. The code is below.
public Complex divide(Complex rhs){
if (rhs.real == 0 && rhs.imag == 0){
return null;}
else if (rhs.real != 0 && rhs.imag == 0){
return new Complex((real/rhs.real), (imag/rhs.real));}
else if (rhs.imag != 0){
double denom = Math.pow(rhs.real, 2) + Math.pow(rhs.imag, 2);
double numr = (real * rhs.real) - (imag *rhs.imag);
double numi = (real*rhs.imag) + (rhs.real + imag);
return new Complex(numr/denom, numi/denom);}
}