Question: Write a class Complex to represent complex numbers in java. Objects of the type Complex should be described to to fields, re and im of

Write a class Complex to represent complex numbers in java.

Objects of the type Complex should be described to to fields, re and im of the type double. The two fields re and im should be declared as private due to the constuction of the class. (fx if you later want to change to polar representation)

The class has to contain the following methods:

public Complex(double re, double im). A constructor for creating a new Complex-object with real part re and imaginary part im.

public Complex(Complex z). A constructor for creating a new Complex-object representing the same complex number as z.

public double getRe(). Returns the real part of the Complex-object.

public double getIm(). Returns the imaginary part of the Complex-object.

public double abs(). Returns modulus of the Complex-object. (?re2+im2)

public Complex plus(Complex other). Returns a Complex-object representing the sum of the current Complex-object and the Complex-object other. Remember: (a+bi)+(c+di) = (a+c)+(b+d)i

public Complex times(Complex other). Returns a Complex-object representing the product of the current Complex-object and the Complex-object other. Remember: (a+bi)(c+di) = (ac?bd)+(bc+ad)i

public Complex divide(Complex other). Returns a Complex-object representing the division of the current Complex-object and the Complex-object other. Remember:  Write a class Complex to represent complex numbers in java. Objects

public String toString(). Returns a string that represents the Complex-object in proper form (fx. the form "a + ib").

a+bi 2 = (ac + bd) + (bc ad) c2 + d2 C+ di

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!