Free University of Bolzano/Bozen
Faculty of Computer Science - Bachelor in Applied Computer Science
Bachelor in Production Engineering
Introduction to Programming - A.A. 2004/2005
Exercise
Class ComplexNumber
Part 1: Design and realize a Java class
ComplexNumber
to represent complex numbers. The functionalities
of interest for complex numbers are the following:
- creation of a complex number starting from two real numbers representing
respectively the real and the imaginary parts.
- real: returns the real part of the complex number.
- imaginary: returns the imaginary part of the complex
number.
- module: returns the module of the complex number.
- phase: returns the phase of the complex number.
- equalTo: verifies whether two complex numbers are equal.
- sum: returns the sum of two complex numbers.
- difference returns the difference of two complex numbers.
- product: returns the product of two complex numbers.
- quotient returns the quotient of two complex numbers.
Add to the class also a method that does overriding of
toString
inherited from Object
in such a way that it
returns a string representing in a suitable way a complex number.
Part 2: Write a public static method external to the class
ComplexNumber
that, taken a complex number as parameter, returns
an integer between 0 and 4 representing the quadrant in which the complex
number falls. The result should be 0 in case the complex number lies on one of
the two axes.