Created
October 19, 2023 14:16
-
-
Save alexaleluia12/63f43e52f9d22341e2cad32ec7d02b47 to your computer and use it in GitHub Desktop.
Google PlayGround
This file contains hidden or 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
fun main() { | |
val amanda = Person("Amanda", 33, "play tennis", null) | |
val atiqah = Person("Atiqah", 28, "climb", amanda) | |
amanda.showProfile() | |
atiqah.showProfile() | |
} | |
class Person(val name: String, val age: Int, val hobby: String?, val referrer: Person?) { | |
fun showProfile() { | |
val msg = "Name: $name\nIdade: $age\n${hobbyMsg()} ${referrerMsg()}\n" | |
println(msg) | |
} | |
private fun myReferrerMsg() = "Has a referrer named $name how likes to $hobby." | |
private fun hobbyMsg() = if (hobby != null) "Likes to $hobby." else "" | |
private fun referrerMsg() = if (referrer == null) "Does not have a referrer" else referrer?.myReferrerMsg() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment