Advertisement
Guest User

Untitled

a guest
May 14th, 2018
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Scala 0.39 KB | None | 0 0
  1.     trait Bonus {
  2.         def apply(baseValue: float)(value: float) -> float
  3.         def order: int
  4.     }
  5.    
  6.     class PercentBonus(value: Int) extends Bonus {
  7.         @override
  8.         def apply(baseValue: float) -> baseValue * (1 + value / 100)
  9.         def order = 10
  10.     }
  11.    
  12.     def addBonus(bonus: Bonus) = bonuses.add(bonus)
  13.    
  14.     def getValue = bonuses.orderBy(_.order).fold(baseValue, (value, bonus) -> bonus.apply(value))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement