Last active
June 1, 2018 08:41
-
-
Save ivalexandru/ee2523c5e2fbc15e24f77c5f996e19bf to your computer and use it in GitHub Desktop.
Kotlin_functii_compacte2 (user inputs text to be used as a function parameter)
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
package quizzz | |
fun main(args: Array<String>) { | |
println(isVeryHot(36)) //true | |
// println(whatShouldIDoToday("happy", "sunny")) | |
// println(whatShouldIDoToday("sad")) | |
print("How do you feel?") | |
println(whatShouldIDoToday(readLine()!!)) | |
} | |
//var mai simpla dar nerecomandata cand vei avea programele mai complicate pt ca performanta si mentenanta | |
//fun whatShouldIDoToday(mood: String, weather: String = "sunny", temperature: Int = 24): String{ | |
// return when { | |
// mood == "happy" && weather == "sunny" -> "go for a walk" | |
// mood == "sad" && weather == "rainy" && temperature == 0 -> "stay in bed" | |
// temperature > 35 -> "go swimming" | |
// else -> "Stay home and read." | |
// } | |
//var cu functii compacte: | |
fun isVeryHot (temperature: Int): Boolean = temperature > 35 | |
fun isSadRainyCold (mood: String, weather: String, temperature: Int): Boolean = | |
mood == "sad" && weather == "rainy" && temperature == 0 | |
fun isHappySunny (mood: String, weather: String): Boolean = mood == "happy" && weather == "sunny" | |
fun whatShouldIDoToday(mood: String, weather: String = "sunny", temperature: Int = 24) : String { | |
return when { | |
isVeryHot(temperature) -> "go swimming" | |
isSadRainyCold(mood, weather, temperature) -> "stay in bed" | |
isHappySunny(mood, weather) -> "go for a walk" | |
else -> "Stay home and read." | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment