package exercises; /** * * @author Lefteris Moussiades */ public class Complex { private double real; private double imaginary; public Complex(double real, double imaginary) { this.real = real; this.imaginary = imaginary; } public double getImaginary() { return imaginary; } public void setImaginary(double imaginary) { this.imaginary = imaginary; } public double getReal() { return real; } public void setReal(double real) { this.real = real; } public Complex add(Complex op) { double r=real+op.real; double i=imaginary+op.imaginary; return new Complex(r,i); } public Complex subtract(Complex op) { double r=real-op.real; double i=imaginary-op.imaginary; return new Complex(r,i); } public Complex multiply(Complex op) { double r=real*op.real; double i=imaginary*op.imaginary; return new Complex(r,i); } public Complex divide(Complex op) { double r=real/op.real; double i=imaginary/op.imaginary; return new Complex(r,i); } public static void main(String[] args) { Complex c1=new Complex(2, 3), c2=new Complex(1, 7); Complex sum=c1.add(c2), diaf=c1.subtract(c2), product=c1.multiply(c2), piliko=c1.divide(c2); System.out.println(sum.getReal()+"+"+sum.getImaginary()+"i"); } }