Created
October 2, 2012 06:26
-
-
Save agushuley/3816779 to your computer and use it in GitHub Desktop.
Scala for impatients, chapter 5, 1th task
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Counter { | |
private var counter: Int = 0; | |
def increment(): Int = { | |
if ( counter == Int.MaxValue ) { | |
counter = 0 | |
} else { | |
counter += 1 | |
} | |
counter | |
} | |
def current = counter | |
def current_= ( value: Int ) { | |
counter = value | |
} | |
} | |
var myCounter = new Counter() | |
myCounter.current | |
myCounter.increment() | |
myCounter.current | |
myCounter.current = Int.MaxValue | |
myCounter.current | |
myCounter.increment() | |
myCounter.current |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment