danielpetisme

Untitled

Dec 6th, 2012
45
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. class Complex {
  2.   Double re
  3.   Double im
  4.  
  5.  String toString() {
  6.   re + ' + ' + im + 'i'
  7.  }
  8.  
  9.  Complex plus(Complex c) {
  10.   new Complex(re: this.re + c.re, im: this.im + c.im)
  11.  }
  12. }
  13.  
  14. def c1 = new Complex(re:2, im:3.5)
  15. def c2 = new Complex(re:4.2, im:7.1)
  16. println 'c1 : ' + c1
  17. //c1 : 2.0 + 3.5i
  18. println 'c2 : ' + c2
  19. //c2 : 4.2 + 7.1i
  20. def result = c1 + c2
  21. println 'result : ' + result
  22. //result : 6.2 + 10.6i
  23.  
Advertisement
Add Comment
Please, Sign In to add comment