Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I need this written in Java!! Create a ComplexNumber class to represent a comple

ID: 3707064 • Letter: I

Question

I need this written in Java!!

Create a ComplexNumber class to represent a complex number. A complex number is a number that's of the form a+bi, where a and b are real numbers (a,b E R), but i V-1, also called the imaginary n if you need a refresher Check Wikipedia The fields for a ComplexNumber should be a and b. Create a constructor that initializes values for both a and b. Create instance methods add, subtract, multiply, and divide. Each of these methods will take in one other ComplexNumber and performs the stated operation to produce a new ComplexNumber For example, the add method should look like this: public ComplexNumber add(ComplexNumber other) t Demo by creating some complex numbers and testing them out

Explanation / Answer

program:

class ComplexNumber

{

double a,b;

ComplexNumber(double a,double b)

{

this.a=a;

this.b=b;

}

public ComplexNumber add(ComplexNumber C1)

{

ComplexNumber Sum=new ComplexNumber();

Sum.a=a+C1.a;

Sum.b=b+C1.b;

System.out.println("SUM:" + C2.a + "+i" +C2.b);

}

public ComplexNumber sub(ComplexNumber C1)

{

ComplexNumber Diff=new ComplexNumber();

Diff.a=a-C1.a;

Diff.b=b-C1.b;

System.out.println("DIFF:" + C2.a + "+i" +C2.b);

}

public ComplexNumber product(ComplexNumber C1)

{

ComplexNumber Mul=new ComplexNumber();

Mul.a=a*(C1.a);

Mul.b=b*(C1.b);

System.out.println("MUL:" + C2.a + "+i" +C2.b);

}

public ComplexNumber div(ComplexNumber C1)

{

ComplexNumber Div=new ComplexNumber();

Div.a=a/(C1.a);

Div.b=b/(C1.b);

System.out.println("DIV:" + C2.a + "+i" +C2.b);

}

Class ComplexNumbermain

{

public static void main(String[] s)

{

ComplexNumber C=new ComplexNumber(10,20);

ComplexNumber C1=new ComplexNumber(20,40);

ComplexNumber C2=new ComplexNumber();

C2=C2.add(C1);

C2=C2.sub(C1);

C2=C2.product(C1);

C2=C2.div(C1);

}

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote