/** * Write a description of class NumComplejo here. * * @author (your name) * @version (a version number or a date) */ public class NumComplejo { private double real; private double img; public NumComplejo() { this(0.0,0.0); } public NumComplejo(double r) { this(r,0.0); } public NumComplejo(double r, double i) { real = r; img = i; } public double obtReal() { return real; } public double obtImg() { return img; } public boolean sonIguales(NumComplejo otro) { return real == otro.real && img == otro.img; } public NumComplejo sumar(NumComplejo operDer) { return new NumComplejo(real + operDer.real, img + operDer.img); } public NumComplejo escalar(double r) { return new NumComplejo(real * r, img * r); } public NumComplejo multiplicar(NumComplejo operDer) { double real = this.real * operDer.real - this.img * operDer.img; double img = this.real * operDer.img + this.img * operDer.real; return new NumComplejo(real, img); } public NumComplejo restar(NumComplejo operDer) { return new NumComplejo(real - operDer.real, img - operDer.img); } public NumComplejo dividir(NumComplejo operDer) { final double DOS = 2.0; double dem = Math.pow(operDer.real, DOS) + Math.pow(operDer.img, DOS); double real = (this.real * operDer.real + this.img * operDer.img); real /= dem; double img = (this.img * operDer.real - this.real * operDer.img); img /= dem; return new NumComplejo(real, img); } }