Skip to Main Content

New to Java

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Dividing a complex number. Need help with the method format.

807601Feb 5 2008 — edited Feb 5 2008
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);}

}
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Mar 4 2008
Added on Feb 5 2008
9 comments
244 views