Skip to content

Instantly share code, notes, and snippets.

@alexaleluia12
Created October 19, 2023 12:36
Show Gist options
  • Save alexaleluia12/93c0e35c6a36fd94a9ea4f5e91ae0a3a to your computer and use it in GitHub Desktop.
Save alexaleluia12/93c0e35c6a36fd94a9ea4f5e91ae0a3a to your computer and use it in GitHub Desktop.
Google PlayGround
fun main() {
val child = 5
val adult = 28
val senior = 87
val isMonday = true
println("The movie ticket price for a person aged $child is \$${ticketPrice(child, isMonday)}.")
println("The movie ticket price for a person aged $adult is \$${ticketPrice(adult, isMonday)}.")
println("The movie ticket price for a person aged $senior is \$${ticketPrice(senior, isMonday)}.")
println("Price to 60 years on monday = \$${ticketPrice(60, true)}")
println("Price to 61 years not on monday = \$${ticketPrice(61, false)}")
}
fun ticketPrice(age: Int, isMonday: Boolean): Int {
if (age > 100 ) return -1
return when {
age >= 61 -> 20
age >= 13 -> if (isMonday) 25 else 30
else -> 15
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment