Kotlin - Clock WIP

This commit is contained in:
Anthony C 2017-08-12 14:07:24 -04:00
parent 6dceb1b807
commit 498800658b

View file

@ -0,0 +1,33 @@
data class Clock(var hours: Int, var minutes: Int) {
init {
val minutesTemp = minutes.rem(60)
var extraHours = minutes.div(60)
if (minutesTemp < 0){
extraHours--
this.minutes = 60 + minutesTemp
} else this.minutes = minutesTemp
val hoursTemp = (hours + extraHours).rem(24)
this.hours = if (hoursTemp < 0){ 24 + hoursTemp } else hoursTemp
}
private fun addMinutes(x: Int): Unit {
if (x > 59){
}
}
private fun addHours(x: Int): Unit {
}
fun add(i: Int) {
this.addMinutes(i)
this.addHours(i.div(60))
}
override fun toString(): String {
return "${if (hours > 9){ "$hours"} else {"0$hours"}}:${if (minutes > 9){ "$minutes"} else {"0$minutes"}}"
}
}