Created
October 2, 2012 07:37
-
-
Save agushuley/3817075 to your computer and use it in GitHub Desktop.
Scala for impatients, chapter 5, 4th 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 Time( private val _hour: Int, private val _minute: Int ) { | |
private val time = _hour * 60 + _minute; | |
def hour = _hour | |
def minute = _minute | |
def before( other: Time ) = other.time > time | |
override def toString(): String = hour + ":" + minute | |
} | |
val time1 = new Time( 1, 10 ) | |
val time2 = new Time( 2, 10 ) | |
val time3 = new Time( 1, 11 ) | |
println( time1 + " before " + time2 + "? " + time1.before( time2 ) ) | |
println( time2 + " before " + time1 + "? " + time2.before( time1 ) ) | |
println( time1 + " before " + time3 + "? " + time1.before( time3 ) ) | |
println( time3 + " before " + time1 + "? " + time3.before( time1 ) ) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment