/*
 * Created on 13-Dec-2004 by @author fischer
 *
 * $Log: KomplexeZahl.java,v $
 * Revision 1.1  2005/01/04 07:49:05  fischer
 * Musterlösung A10
 *
 * Revision 1.2  2004/12/21 10:37:16  kretschmer
 * *** empty log message ***
 *
 * Revision 1.1  2004/12/13 16:00:42  fischer
 * Musterlösungen Blatt 10
 *
 * 
 * $Revision: 1.1 $
 */
package de.unidue.is.prog.woche10;

/**
 * @author fischer
 */
public class KomplexeZahl {
	
	private double r; // reeller Teil
	private double i; // imaginärer Teil
	
	public KomplexeZahl(double r, double i) {
		this.r=r;
		this.i=i;
	}
	
	public double getReal() {
		return r;
	}
	
	public double getImaginary() {
		return i;
	}
	
	public KomplexeZahl add(KomplexeZahl c) {
		return new KomplexeZahl(this.getReal()+c.getReal(),this.getImaginary()+c.getImaginary());
	}
	
	public KomplexeZahl mul(KomplexeZahl c) {
		return new KomplexeZahl(this.getReal()*c.getReal()-this.getImaginary()*c.getImaginary(),
				this.getReal()*c.getImaginary()+this.getImaginary()*c.getReal());
	}
	
	public boolean equals(Object o) {
		return ((o instanceof KomplexeZahl) &&
				(((KomplexeZahl)o).getReal()==this.getReal()) &&
				(((KomplexeZahl)o).getImaginary()==this.getImaginary()));
	}

	public boolean equalDist(Object o) {
		return ((o instanceof KomplexeZahl) &&
				(Math.pow(((KomplexeZahl)o).getReal(),2)+Math.pow(((KomplexeZahl)o).getImaginary(),2)==Math.pow(this.getReal(),2)+Math.pow(this.getImaginary(),2))
				);
	}

	public static void main (String args[]){
		KomplexeZahl a=new KomplexeZahl(1, 1);
		KomplexeZahl b=new KomplexeZahl(1, 1);
		KomplexeZahl c=new KomplexeZahl(1, -1);
		System.out.println(a.equals(b));
		System.out.println(a.equals(c));
		System.out.println(a.equalDist(c));
	}
	
}
