-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path06-when.kt
31 lines (27 loc) · 838 Bytes
/
06-when.kt
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
enum class Console(val year: Int) {
GBA(2003),
PLAYSTATION(2000),
XBOX(2005),
SWITCH(2017),
PC(1946)
}
fun getPrice(console: Console): Int =
when (console) {
Console.GBA -> 1000
Console.PLAYSTATION -> 5299
Console.SWITCH -> 2500
Console.XBOX -> 4200
Console.PC -> 5000
}
fun haveDiscount(console: Console): String {
return when (console) {
Console.GBA, Console.SWITCH, Console.PC -> "have discount"
Console.PLAYSTATION, Console.XBOX -> "not have discount"
}
}
fun main() {
val price = getPrice(Console.PLAYSTATION)
println("Console price is R$$price and this console ${haveDiscount(Console.PLAYSTATION)}")
val pricePC = getPrice(Console.PC)
println("Console price is R$$pricePC and this console ${haveDiscount(Console.PC)}")
}