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:
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+ diStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started