CSE1030 Lab 02

Week of Jan 20, 2014
Due: Mon Jan 27 before 11:59PM

Introduction

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.

Question 1: Complex Numbers

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. - 1 = i

A complex number is a number that can be written as a + b i 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 a + b i + c + d i = a + c + b + d i 3 + 3 i + 5 - 5 i = 8 - 2 i
multiplication a + b i × c + d i = a c - b d + b c + a d i 1 + 3 i × 2 + 2 i = 1 · 2 - 3 · 2 + 3 · 2 + 1 · 2 i = - 4 + 8 i
magnitude a + b i = a 2 + b 2 1 + 2 i = 1 2 + 2 2 = 5

Implement a class named Complex in the package cse1030.math that represents immutable complex numbers. Some resources you will need are listed below:

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:

The test program

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

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/