-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathInternetProfile.kt
More file actions
32 lines (27 loc) · 1.05 KB
/
InternetProfile.kt
File metadata and controls
32 lines (27 loc) · 1.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
fun main() {
val amanda = Person("Amanda", 33, "play tennis", null)
val atiqah = Person("Atiqah", 28, "climb", amanda)
val kotlin = Person("kotlin", 32, null, null)
kotlin.showProfile()
amanda.showProfile()
atiqah.showProfile()
}
class Person(val name: String, val age: Int, val hobby: String?, val referrer: Person?) {
fun showProfile() {
println("name: ${name}")
println("Age: ${age}")
checkForHobbyAndRef(hobby, referrer)
println()
}
private fun checkForHobbyAndRef(personHobby: String?, referrer: Person?) {
var hasHobbyRes = checkHobby(personHobby)
var referreRes: String = "Doesn't have a referrer"
if(referrer != null) {
referreRes = "Has referrer named ${referrer.name} who ${checkHobby(referrer.hobby)}"
}
println("${hasHobbyRes} ${referreRes}")
}
private fun checkHobby(text: String?): String {
return if (text != null) "Likes to ${text}. " else "Has No hobbies. "
}
}