Advertisement
Guest User

Untitled

a guest
Oct 7th, 2014
169
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Scala 0.67 KB | None | 0 0
  1. package o1.football2
  2.  
  3. import scala.collection.mutable.Buffer
  4. import scala.math._
  5.  
  6. class Season {
  7.    
  8.   private val matches = Buffer[Match]()
  9.    
  10.   def addResult(result: Match) = matches += result
  11.    
  12.   def biggestWin = {
  13.     var win: Option[Match] = None
  14.     var margin = 0
  15.     for (game <- matches) {
  16.       if (abs(game.goalDifference) > margin){
  17.         margin = abs(game.goalDifference)
  18.         win = Some(game)
  19.       }    
  20.     }
  21.     win
  22.   }
  23.  
  24.   def latestMatch = {
  25.     if (matches.size == 0)
  26.       None
  27.     else
  28.       Some(matches(matches.size - 1))
  29.   }
  30.    
  31.   def matchNumber(number: Int) = matches(number)
  32.    
  33.   def numberOfMatches = matches.size
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement