Skip to content

Instantly share code, notes, and snippets.

@agushuley
Created October 2, 2012 07:37
Show Gist options
  • Save agushuley/3817075 to your computer and use it in GitHub Desktop.
Save agushuley/3817075 to your computer and use it in GitHub Desktop.
Scala for impatients, chapter 5, 4th task
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