User:Simpsons contributor/ComplexOperations class

package newtonsmethodfractal;

/*Performs arithmetic operations on * complex numbers*/

public class ComplexOperations {   public Complex add(Complex number1, Complex number2) {       //Create new complex number to be returned Complex result = new Complex; /*Get the real and imaginary parts from * the two complex numbers to be added*/ int realInt1 = number1.realInt; int realInt2 = number2.realInt; double realDouble1 = number1.realDouble; double realDouble2 = number2.realDouble; int imaginaryInt1 = number1.imaginaryInt; int imaginaryInt2 = number2.imaginaryInt; double imaginaryDouble1 = number1.imaginaryDouble; double imaginaryDouble2 = number2.imaginaryDouble; /*Perform arithmatic operation on the int and double * components, then set the output number's real and imaginary * numbers*/ int realIntOut = realInt1 + realInt2; int imaginaryIntOut = imaginaryInt1 + imaginaryInt2; double realDoubleOut = realDouble1 + realDouble2; double imaginaryDoubleOut = imaginaryDouble1 + imaginaryDouble2; result.setReal(realIntOut); result.setReal(realDoubleOut); result.setImaginary(imaginaryIntOut); result.setImaginary(imaginaryDoubleOut); return result; }   public Complex subtract(Complex number1, Complex number2) {       //Complex number1 - complex number 2 //Create new complex number to be returned Complex result = new Complex; /*Get the real and imaginary parts from * the two complex numbers to be subtracted*/ int realInt1 = number1.realInt; int realInt2 = number2.realInt; double realDouble1 = number1.realDouble; double realDouble2 = number2.realDouble; int imaginaryInt1 = number1.imaginaryInt; int imaginaryInt2 = number2.imaginaryInt; double imaginaryDouble1 = number1.imaginaryDouble; double imaginaryDouble2 = number2.imaginaryDouble; /*Perform arithmatic operation on the int and double * components, then set the output number's real and imaginary * numbers*/ int realIntOut = realInt1 - realInt2; int imaginaryIntOut = imaginaryInt1 - imaginaryInt2; double realDoubleOut = realDouble1 - realDouble2; double imaginaryDoubleOut = imaginaryDouble1 - imaginaryDouble2; result.setReal(realIntOut); result.setReal(realDoubleOut); result.setImaginary(imaginaryIntOut); result.setImaginary(imaginaryDoubleOut); return result; }   public Complex multiply(Complex number1, Complex number2) {       //Create new complex number to be returned Complex result = new Complex; /*Get the real and imaginary parts from * the two complex numbers to be multiplied*/ int realInt1 = number1.realInt; int realInt2 = number2.realInt; double realDouble1 = number1.realDouble; double realDouble2 = number2.realDouble; int imaginaryInt1 = number1.imaginaryInt; int imaginaryInt2 = number2.imaginaryInt; double imaginaryDouble1 = number1.imaginaryDouble; double imaginaryDouble2 = number2.imaginaryDouble; /*Perform arithmatic operation on the int and double * components, then set the output number's real and imaginary * numbers*/ int realIntOut = (realInt1*realInt2) - (imaginaryInt1*imaginaryInt2); int imaginaryIntOut = (imaginaryInt1*realInt2) + (realInt1*imaginaryInt2); double realDoubleOut = (realDouble1*realDouble2) - (imaginaryDouble1*imaginaryDouble2); double imaginaryDoubleOut = (imaginaryDouble1*realDouble2) + (realDouble1*imaginaryDouble2); result.setReal(realIntOut); result.setReal(realDoubleOut); result.setImaginary(imaginaryIntOut); result.setImaginary(imaginaryDoubleOut); return result; }   public Complex divide(Complex number1, Complex number2) {       //Complex number 1 / complex number 2 int realIntOut = 0; int imaginaryIntOut = 0; double realDoubleOut = 0; double imaginaryDoubleOut = 0; //Create new complex number to be returned Complex result = new Complex; /*Get the real and imaginary parts from * the two complex numbers to be divided*/ int realInt1 = number1.realInt; int realInt2 = number2.realInt; double realDouble1 = number1.realDouble; double realDouble2 = number2.realDouble; int imaginaryInt1 = number1.imaginaryInt; int imaginaryInt2 = number2.imaginaryInt; double imaginaryDouble1 = number1.imaginaryDouble; double imaginaryDouble2 = number2.imaginaryDouble; /*Test to see if the denominator is equal to zero * in the int or double operations. Set to true if         * it isn't (carry out operation), set to false if         * it is (don't carry out operation).*/ boolean zeroIntTest = true; boolean zeroDoubleTest = true; int intTest = (realInt2*realInt2) + (imaginaryInt2*imaginaryInt2); double doubleTest = (realDouble2*realDouble2) + (imaginaryDouble2*imaginaryDouble2); if(intTest == 0) zeroIntTest = false; if(doubleTest == 0) zeroDoubleTest = false; /*Perform arithmatic operation on the int and double * components, then set the output number's real and imaginary * numbers*/ if(zeroIntTest == true) {           realIntOut = ((realInt1*realInt2) + (imaginaryInt1*imaginaryInt2)) / ((realInt2*realInt2) + (imaginaryInt2*imaginaryInt2)); imaginaryIntOut = ((imaginaryInt1*realInt2) - (realInt1*imaginaryInt2)) / ((realInt2*realInt2) + (imaginaryInt2*imaginaryInt2)); }       if(zeroDoubleTest == true) {               realDoubleOut = ((realDouble1*realDouble2) + (imaginaryDouble1*imaginaryDouble2)) / ((realDouble2*realDouble2) + (imaginaryDouble2*imaginaryDouble2)); imaginaryDoubleOut = ((imaginaryDouble1*realDouble2) - (realDouble1*imaginaryDouble2)) / ((realDouble2*realDouble2) + (imaginaryDouble2*imaginaryDouble2)); }       result.setReal(realIntOut); result.setReal(realDoubleOut); result.setImaginary(imaginaryIntOut); result.setImaginary(imaginaryDoubleOut); return result; } }