Created
October 19, 2023 12:36
-
-
Save alexaleluia12/93c0e35c6a36fd94a9ea4f5e91ae0a3a 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 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