import java.lang.Math;
import java.math.BigDecimal;

public class ComplexNumber
{
    private double re, im;	
    
	// makes a new  ComplexNumber equal to 0 + 0i
    public ComplexNumber() 
	{ 
        re = 0;
        im = 0;
    }
    
	// makes a new ComplexNumber given a double as the real part, and 0 as the imaginary part
    public ComplexNumber(double x) 
	{ 
        re = x;
        im = 0;
    }
    
	// makes a new ComplexNumber given two doubles as the real and imaginary part
	public ComplexNumber(double r, double i) 
	{
        re = r;
        im = i;
    }	
	
	// returns real part of a ComplexNumber
	public double real(ComplexNumber z)
	{
		return z.re;
	}

	// returns imaginary part of a ComplexNumber
	public double imag(ComplexNumber z)
	{
		return z.im;
	}
	
	// complex multiplication
    public ComplexNumber mult(ComplexNumber z) 
	{
		return new ComplexNumber((this).re*z.re - (this).im*z.im , (this).re*z.im + (this).im*z.re );
    }

	// complex addition
    public ComplexNumber add(ComplexNumber z) 
	{
        return new ComplexNumber( (this).re + z.re, (this).im + z.im);
    }    
    
	// complex subtraction
    public ComplexNumber sub(ComplexNumber z) 
	{
        return new ComplexNumber( (this).re - z.re, (this).im - z.im);
    }

	// complex division
    public ComplexNumber div(ComplexNumber z) 
	{
	
		//make sure z != 0
		if( (z.re)==0 && (z.im)==0 )
		{
			System.out.println("oops, divided by 0!");
			return null;
		}
		else 
		{
			double s = z.normSq();
			return new ComplexNumber( ((this).re*z.re + (this).im*z.im)/s, ((this).im*z.re - (this).re*z.im)/s);
		}
    }

	// complex conjuate
    public ComplexNumber conj() 
	{
        return new ComplexNumber((this).re, -(this).im);
    }
    
	// norm squared of a complex number
	public double normSq()
	{
		return (this).re*(this).re + (this).im*(this).im;
	}
	
	// negative of the complex number
    public ComplexNumber neg() 
    {
        return new ComplexNumber(-(this).re, -(this).im);
    }

	// a string version of the number, in tuple form
    public String toString() {
        return "(" + (this).re + "," + (this).im + ")";        
    }
	
	// return real part
	public double real()
	{
		return (this).re;
	}	
		
	// return imaginary part
	public double imag()
	{
		return (this).im;
	}	
	
	// squares a complex number
	public ComplexNumber square()
	{
		return (this).mult((this));
	}	
	
	// cubes a complex number
	public ComplexNumber cube()
	{
		return (this).mult((this).mult(this));
	}
	
	// sets the real part of a complex number
	public void setReal(double x)
	{
		(this).re = x;
	}	
	
	// sets the imaginary part of a complex number
	public void setImag(double y)
	{
		(this).im = y;
	}
}