Week of Jan 20, 2014

Due: Mon Jan 27 before 11:59PM

The purpose of this lab is to implement an immutable class, which includes adding documentation in the form of Javadoc comments and generating APIs using the Javadoc tool, as well as testing against a set of unit tests.

Complex numbers arise when you try to compute a root of a negative number.
For example, the square root of `-1`

is not a real number; however,
mathematicians have found that it is very useful to say that there exists
some number (not real) that is the square root of `-1`

. Historically,
such a number was called "fictitious" or "imaginary", and is now written
as the symbol *i*.
$$\sqrt{-1}=i$$

A complex number is a number that can be written as $$a+bi$$ where $a$ and $b$ are real numbers. The $a$ is called the real part of the complex number, and the $b$ is called the imaginary part of the complex number.

Complex numbers turn out to be very useful in mathematics (complex analysis, for example), physics (in the study of waves, electromagnetism, and quantum mechanics, for example), the study of signals (signal and image processing, for example), ...

Here are some elementary operations that you can do with complex numbers:

Operation | Definition | Example |
---|---|---|

addition | $\left(a+bi\right)+\left(c+di\right)=\left(a+c\right)+\left(b+d\right)i$ | $\left(3+3i\right)+\left(5-5i\right)=8-2i$ |

multiplication | $\left(a+bi\right)\times \left(c+di\right)=\left(ac-bd\right)+\left(bc+ad\right)i$ | $\left(1+3i\right)\times \left(2+2i\right)=\left(1\xb72-3\xb72\right)+\left(3\xb72+1\xb72\right)i=-4+8i$ |

magnitude | $\left|\left(a+bi\right)\right|=\sqrt{{a}^{2}+{b}^{2}}$ | $\left|\left(1+2i\right)\right|=\sqrt{{1}^{2}+{2}^{2}}=\sqrt{5}$ |

Implement a class named `Complex`

in the package `cse1030.math`

that represents immutable complex numbers. Some resources you will need are
listed below:

- the API for
`Complex`

- a JUnit tester
- a test program
`Mandelbrot`

that uses`Complex`

to draw the Mandelbrot set - a jar file for Mandebrot test program.
Download the JAR file and add it to your project:
- select the
`Project`

menu - select
`Properties`

- on the left side of the dialog that appears, select
`Java Build Path`

- on the right, select the
`Libraries`

tab - click the
`Add External JARs...`

button - add the jar file you downloaded

- select the

Also, here is some starter code for `Complex`

:

```
package cse1030.math;
/**
* A class that represents immutable complex numbers.
*
* @author CSE1030_W14
*
*/
public final class Complex {
private final double re; // the real part of this complex number
private final double im; // the imaginary part of this complex number
/**
* Create a complex number equal to
````0 + 0i`

.
*
*/
public Complex() {
this.re = 0.0;
this.im = 0.0;
}
}

Here are some hints to help you with your work:

- Eclipse will generate acceptable versions of
`hashCode`

and`equals`

- Your class should include the necessary Javadoc comments to reproduce the API.
- If you cannot complete one or more of the methods, at least make sure that it
returns some value of the correct type; this will allow the tester to run, and it will
make it much easier to evaluate your code. For example, if you are having difficulty
with the method
`fromPolar`

then make sure that it returns a`Complex`

number created using the default constructor.

Perhaps the most widely seen visualization based on complex numbers is the
Mandelbrot set. Once you have implemented and tested the `Complex`

class, you can run the Java program `Mandelbrot`

that computes and draws a Mandelbrot set. You should get the following output:

Submit your work using the following command in the directory where your `Complex.java`

file is saved.

submit 1030 L2 Complex.java

or use the web-based submit https://webapp.eecs.yorku.ca/submit/