-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.kt
More file actions
74 lines (66 loc) · 2.16 KB
/
main.kt
File metadata and controls
74 lines (66 loc) · 2.16 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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
open class BcsdLabUser(val emoji: String, val name: String)
class Beginner(emoji: String, name: String, val fail: Int) : BcsdLabUser(emoji, name) {
fun printStatus() {
println(emoji +" "+ name + " Number of fail: " + fail)
}
}
class Regular(emoji: String, name: String, val pay: Boolean) : BcsdLabUser(emoji, name) {
fun printStatus() {
val payment = if (pay) "paid" else "unpaid"
println(emoji + " "+ name + " payment of membership fees: " + payment)
}
}
class Mentor(emoji: String, name: String, val email: String?) : BcsdLabUser(emoji, name) {
fun printStatus() {
val mail = if (email.isNullOrEmpty()) "None" else email
println(emoji + " "+ name + " email: " + mail)
}
}
fun main() {
val users: List<BcsdLabUser> = listOf(
Beginner("🌱", "KimYeran", 0),
Beginner("🌱", "LeeYejin", 1),
Beginner("🌱", "ParkYerin", 2),
Beginner("🌱", "YangYechan", 3),
Regular("🍏", "ChoiYein", false),
Regular("🍏", "JungYehan", false),
Regular("🍏", "HanYesung", true),
Mentor("⭐", "YangYewon", "yang@gmail.com"),
Mentor("⭐", "NaYeyoung", null)
)
println("All Beginners: ")
for (user in users) {
if (user is Beginner) {
user.printStatus()
}
}
println("\nBeginners who failed 3 or more tasks: ")
for (user in users) {
if (user is Beginner)
if (user.fail >= 3){
user.printStatus()
}
}
println("\nRegular members who haven't paid: ")
for (user in users){
if (user is Regular) {
if (!user.pay) {
user.printStatus()
}
}
}
println("\nUsers with last name 'Yang':")
for (user in users) {
if (user.name.startsWith("Yang")) {
if (user is Beginner) {
user.printStatus()
}
else if (user is Regular) {
user.printStatus()
}
else if (user is Mentor) {
user.printStatus()
}
}
}
}