Skip to content

Instantly share code, notes, and snippets.

@alexaleluia12
Created October 19, 2023 14:16
Show Gist options
  • Save alexaleluia12/63f43e52f9d22341e2cad32ec7d02b47 to your computer and use it in GitHub Desktop.
Save alexaleluia12/63f43e52f9d22341e2cad32ec7d02b47 to your computer and use it in GitHub Desktop.
Google PlayGround
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