Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package o1.football2
- import scala.collection.mutable.Buffer
- import scala.math._
- class Season {
- private val matches = Buffer[Match]()
- def addResult(result: Match) = matches += result
- def biggestWin = {
- var win: Option[Match] = None
- var margin = 0
- for (game <- matches) {
- if (abs(game.goalDifference) > margin){
- margin = abs(game.goalDifference)
- win = Some(game)
- }
- }
- win
- }
- def latestMatch = {
- if (matches.size == 0)
- None
- else
- Some(matches(matches.size - 1))
- }
- def matchNumber(number: Int) = matches(number)
- def numberOfMatches = matches.size
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement