-
Notifications
You must be signed in to change notification settings - Fork 0
/
SimpleBot.kt
62 lines (52 loc) · 1.63 KB
/
SimpleBot.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
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
package bot
import java.util.Scanner
val scanner = Scanner(System.`in`) // Do not change this line
fun main() {
greet("Aid", "2020") // change it as you need
remindName()
guessAge()
count()
test()
end()
}
fun greet(assistantName: String, birthYear: String) {
println("Hello! My name is ${assistantName}.")
println("I was created in ${birthYear}.")
println("Please, remind me your name.")
}
fun remindName() {
val name = scanner.nextLine()
println("What a great name you have, ${name}!")
}
fun guessAge() {
println("Let me guess your age.")
println("Enter remainders of dividing your age by 3, 5 and 7.")
val rem3 = scanner.nextInt()
val rem5 = scanner.nextInt()
val rem7 = scanner.nextInt()
val age = (rem3 * 70 + rem5 * 21 + rem7 * 15) % 105
println("Your age is ${age}; that's a good time to start programming!")
}
fun count() {
println("Now I will prove to you that I can count to any number you want.")
val num = scanner.nextInt()
for (i in 0..num) {
print(i)
println("!")
}
}
fun test() {
println("Let's test your programming knowledge.")
println("Why do we use methods?")
println("1. To repeat a statement multiple times.")
println("2. To decompose a program into several small subroutines.")
println("3. To determine the execution time of a program.")
println("4. To interrupt the execution of a program.")
while (scanner.hasNextInt()) {
if (scanner.nextInt() == 2) break
println("Please, try again.")
}
}
fun end() {
println("Congratulations, have a nice day!") // Do not change this text
}