Skip to content

Instantly share code, notes, and snippets.

@delucas
Created April 6, 2017 13:47
Show Gist options
  • Save delucas/7a0204eb6ba00119b1bba1407fff541c to your computer and use it in GitHub Desktop.
Save delucas/7a0204eb6ba00119b1bba1407fff541c to your computer and use it in GitHub Desktop.
public class Complejo {
private double real;
private double imag;
// primero los constructores
public Complejo(double real ,double imag) {
this.real = real;
this.imag = imag;
}
public Complejo() {
this(0,0);
}
public String toString() {
return "Complejo [real=" + real + ", imag=" + imag + "]";
}
// despues agrupamos las funcones aritmeticas
public Complejo suma(Complejo z) {
return(new Complejo(this.real+z.real,this.imag+z.imag));
}
//se debe ir probando todo en el main
public static void main(String[] args) {
Complejo z1 = new Complejo();
Complejo z2 = new Complejo(2,2);
Complejo z3 = new Complejo(1.1,1.1);
System.out.println(z1);
System.out.println(z2);
System.out.println(z3);
z3=z1.suma(z2);
System.out.println(z3); // muestra 2,2
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment