Guest User

Untitled

a guest
Oct 21st, 2018
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.77 KB | None | 0 0
  1. class Retangulo
  2. attr_accessor :largura, :altura
  3. def initialize(l,a)
  4. @largura = l
  5. @altura = a
  6. end
  7.  
  8. def +(other)
  9. Retangulo.new(@largura + other.largura, @altura + other.altura)
  10. end
  11.  
  12. def -(other)
  13. Retangulo.new(@largura - other.largura, @altura - other.altura)
  14. end
  15.  
  16. def /(other)
  17. Retangulo.new(@largura / other.largura, @altura / other.altura)
  18. end
  19.  
  20. def *(other)
  21. Retangulo.new(@largura * other.largura, @altura * other.altura)
  22. end
  23.  
  24. def to_s
  25. "Retângulo de largura #{@largura} e altura #{@altura}"
  26. end
  27. end
  28.  
  29. retangulo_1 = Retangulo.new(5,5)
  30. retangulo_2 = Retangulo.new(10,10)
  31.  
  32. puts retangulo_1
  33. puts retangulo_2
  34. puts retangulo_1 + retangulo_2
  35. puts retangulo_1 - retangulo_2
  36. puts retangulo_1 * retangulo_2
  37. puts retangulo_2 / retangulo_1
Add Comment
Please, Sign In to add comment