﻿/* Programming by Greg Thatcher, http://www.GregThatcher.com */

    function complexNumber (real, imaginary)
    {
        this.real = real;
        this.imaginary = imaginary;
    }
    complexNumber.prototype.GetRadius = function()
    {
        return Math.sqrt((this.real * this.real) + (this.imaginary * this.imaginary));
    }
    complexNumber.prototype.ToString = function()
    {
        return "(" + this.real + " + " + this.imaginary + "i)";
    }
    
    complexNumber.prototype.Multiply = function(y)
    {
        var real;
        var imaginary;
        real        = ((this.real * y.real) - (this.imaginary * y.imaginary));
        imaginary   = ((this.real * y.imaginary) + (this.imaginary * y.real));
        
        var newNumber = new complexNumber(real, imaginary);
        return newNumber;
    }
    
    complexNumber.prototype.Add = function(y)
    {
        var real;
        var imaginary;
        real        = (this.real + y.real);
        imaginary   = (this.imaginary + y.imaginary);
        
        return new complexNumber(real, imaginary);
    }


