Question: Java Programming with Packages Qestion Im having trouble figuring out how to finish the code for this program. It invovles complex numbers and the code

Java Programming with Packages Qestion

Im having trouble figuring out how to finish the code for this program. It invovles complex numbers and the code is comented to help.

package mypackages.types;

/**

* A class to represent a complex number.

* Split into two parts, real and imaginary.

* A complex number us defined as real + imaginary*sqaureroot(-1)

* Squareroot(-1) has the symbol of "i".

* @author Zachary Williams

*/

public class ComplexNumber

{

/**

* The imaginary portion of the complex number.

*/

private double imaginary;

/**

* The real portion of the complex number.

*/

private double real;

/**

* A no argument constructor.

* It defaults imaginary and real parts to 0.0

*/

public ComplexNumber()

{

imaginary = 0.0;

real = 0.0;

}

/**

* Used to create a ComplexNumber with passed real and imaginary values.

* @param realIn Initial real value

* @param imaginaryIn Initial imaginary value

*/

public ComplexNumber(double realIn, double imaginaryIn)

{

real = realIn;

imaginary = imaginaryIn;

}

/**

* Adds this ComplexNumber to a passed ComplexNumber, creating a new ComplexNumber.

* This is done by creating a new ComplexNumber with the two operands' real and imaginary parts summed together.

* @param operand2 ComplexNumber to be added to calling instance of ComplexNumber

* @return ComplexNumber that is the summation of calling and passed instance

*/

public ComplexNumber add(ComplexNumber operand2)

{

ComplexNumber abd = new ComplexNumber(this.real, this.imaginary);

// *** ComplexNumber *** this;

double zzz = abd.real + operand2.real;

double xxx = cde.imaginary + operand2.imaginary;

return new ComplexNumber(zzz, xxx);

}

/**

* Subtracts this ComplexNumber with a passed ComplexNumber, creating a new ComplexNumber.

* This is done by creating a new ComplexNumber with the two operands'

* real and imaginary parts subtracted from each other.

* @param operand2 ComplexNumber to be subtracted from calling instance of ComplexNumber

* @return ComplexNumber that is the difference of calling and passed instance

*/

public ComplexNumber subtract(ComplexNumber operand2)

{

}

/**

* Returns a formated String of the ComplexNumber in the form: real + imaginary * i.

* @overrides toString in class java.lang.Object

* @return formattd String of ComplexNumber

*/

public java.lang.String toString()

{

}

}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!