Advertisement
jsbsan

Elemento

May 23rd, 2014
6,697
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
GAMBAS 2.38 KB | None | 0 0
  1. ' Gambas class file
  2.  
  3. Property nombre As String
  4. Private hnombre As String
  5.  
  6. Property valor As Float
  7. Private hvalor As Float
  8.  
  9. Property peso As Float
  10. Private hpeso As Float
  11.  
  12. Property estrategia As String
  13. Private hestrategia As String
  14.  
  15. Private Function estrategia_Read() As String
  16.  
  17.   Return hestrategia
  18.  
  19. End
  20.  
  21. Private Sub estrategia_Write(Value As String)
  22.  
  23.   hestrategia = Value
  24.  
  25. End
  26.  
  27. Private Function nombre_Read() As String
  28.  
  29.   Return hnombre
  30.  
  31. End
  32.  
  33. Private Sub nombre_Write(Value As String)
  34.  
  35.   hnombre = Value
  36.  
  37. End
  38.  
  39. Private Function valor_Read() As Float
  40.  
  41.   Return hvalor
  42.  
  43. End
  44.  
  45. Private Sub valor_Write(Value As Float)
  46.  
  47.   hvalor = Value
  48.  
  49. End
  50.  
  51. Private Function peso_Read() As Float
  52.  
  53.   Return hpeso
  54.  
  55. End
  56.  
  57. Private Sub peso_Write(Value As Float)
  58.  
  59.   hpeso = Value
  60.  
  61. End
  62.  
  63. Public Sub _new(n As String, v As Float, p As Float) '' n es nombre, v es valor, p es peso
  64.  
  65.   hnombre = n
  66.   hvalor = v
  67.   hpeso = p
  68.  
  69. End
  70.  
  71. Public Function toString() As String
  72.  
  73.   Return "Nombre: " & hnombre & " Valor:" & hvalor & " Peso:" & hpeso
  74.  
  75. End
  76. '---------------------------------------------------------------------------------------
  77. 'definicion del método de comparar (que propiedad compara, en este caso el valor)
  78. '----------------------------------------------------------------------------------------
  79.  
  80. Public Function _compare(otro As Elemento) As Integer
  81.   '--------------------------------------------------------
  82.   'Estrategia el del mayor valor...
  83.   '--------------------------------------------------------
  84.  
  85.   If hestrategia = "mayor_valor" Then
  86.     If otro.valor > Me.valor Then
  87.       Return 1
  88.     Else
  89.       Return 0
  90.      
  91.     Endif
  92.   Endif
  93.  
  94.   '--------------------------------------------------------
  95.   'Estrategia el del menos pesados valor...
  96.   '--------------------------------------------------------
  97.  
  98.   If hestrategia = "menos_peso" Then
  99.     If otro.peso < Me.peso Then
  100.       Return 1
  101.     Else
  102.       Return 0
  103.      
  104.     Endif
  105.   Endif
  106.  
  107.   '--------------------------------------------------------
  108.   ' Estrategia: relacion entre valor/peso del elemento
  109.   '--------------------------------------------------------
  110.   If hestrategia = "coeficiente_valor/peso" Then
  111.     If (otro.valor / otro.peso) > (Me.valor / Me.peso) Then
  112.       Return 1
  113.     Else
  114.       Return 0
  115.     Endif
  116.   Endif
  117.  
  118. End
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement