Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ' Gambas class file
- Property nombre As String
- Private hnombre As String
- Property valor As Float
- Private hvalor As Float
- Property peso As Float
- Private hpeso As Float
- Property estrategia As String
- Private hestrategia As String
- Private Function estrategia_Read() As String
- Return hestrategia
- End
- Private Sub estrategia_Write(Value As String)
- hestrategia = Value
- End
- Private Function nombre_Read() As String
- Return hnombre
- End
- Private Sub nombre_Write(Value As String)
- hnombre = Value
- End
- Private Function valor_Read() As Float
- Return hvalor
- End
- Private Sub valor_Write(Value As Float)
- hvalor = Value
- End
- Private Function peso_Read() As Float
- Return hpeso
- End
- Private Sub peso_Write(Value As Float)
- hpeso = Value
- End
- Public Sub _new(n As String, v As Float, p As Float) '' n es nombre, v es valor, p es peso
- hnombre = n
- hvalor = v
- hpeso = p
- End
- Public Function toString() As String
- Return "Nombre: " & hnombre & " Valor:" & hvalor & " Peso:" & hpeso
- End
- '---------------------------------------------------------------------------------------
- 'definicion del método de comparar (que propiedad compara, en este caso el valor)
- '----------------------------------------------------------------------------------------
- Public Function _compare(otro As Elemento) As Integer
- '--------------------------------------------------------
- 'Estrategia el del mayor valor...
- '--------------------------------------------------------
- If hestrategia = "mayor_valor" Then
- If otro.valor > Me.valor Then
- Return 1
- Else
- Return 0
- Endif
- Endif
- '--------------------------------------------------------
- 'Estrategia el del menos pesados valor...
- '--------------------------------------------------------
- If hestrategia = "menos_peso" Then
- If otro.peso < Me.peso Then
- Return 1
- Else
- Return 0
- Endif
- Endif
- '--------------------------------------------------------
- ' Estrategia: relacion entre valor/peso del elemento
- '--------------------------------------------------------
- If hestrategia = "coeficiente_valor/peso" Then
- If (otro.valor / otro.peso) > (Me.valor / Me.peso) Then
- Return 1
- Else
- Return 0
- Endif
- Endif
- End
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement