|
| 1 | +type: edu |
| 2 | +files: |
| 3 | +- name: src/bot/SimpleBot.kt |
| 4 | + visible: true |
| 5 | + text: | |
| 6 | + package bot |
| 7 | +
|
| 8 | + import java.util.Scanner |
| 9 | +
|
| 10 | +
|
| 11 | + fun main() { |
| 12 | + val scanner = Scanner(System.`in`) |
| 13 | +
|
| 14 | + println("Hello! My name is Aid.") |
| 15 | + println("I was created in 2020.") |
| 16 | + println("Please, remind me your name.") |
| 17 | +
|
| 18 | + val name = scanner.nextLine() |
| 19 | +
|
| 20 | + println("What a great name you have, " + name + "!") |
| 21 | + println("Let me guess your age.") |
| 22 | + println("Enter remainders of dividing your age by 3, 5 and 7.") |
| 23 | +
|
| 24 | + val rem3 = scanner.nextInt() |
| 25 | + val rem5 = scanner.nextInt() |
| 26 | + val rem7 = scanner.nextInt() |
| 27 | + val age = (rem3 * 70 + rem5 * 21 + rem7 * 15) % 105 |
| 28 | +
|
| 29 | + println("Your age is " + age + "; that's a good time to start programming!") |
| 30 | + println("Now I will prove to you that I can count to any number you want.") |
| 31 | +
|
| 32 | + // read a number and count to it here |
| 33 | +
|
| 34 | + println("Completed, have a nice day!") |
| 35 | + } |
| 36 | + learner_created: false |
| 37 | +- name: test/ChattyBotTest.java |
| 38 | + visible: false |
| 39 | + text: | |
| 40 | + import org.hyperskill.hstest.stage.StageTest; |
| 41 | + import org.hyperskill.hstest.testcase.CheckResult; |
| 42 | + import org.hyperskill.hstest.testcase.TestCase; |
| 43 | +
|
| 44 | + import java.util.Collections; |
| 45 | + import java.util.List; |
| 46 | +
|
| 47 | +
|
| 48 | + class Clue { |
| 49 | + int age; |
| 50 | + String name; |
| 51 | + int count; |
| 52 | +
|
| 53 | + Clue(String name, int age, int count) { |
| 54 | + this.age = age; |
| 55 | + this.name = name; |
| 56 | + this.count = count; |
| 57 | + } |
| 58 | + } |
| 59 | +
|
| 60 | +
|
| 61 | + public class ChattyBotTest extends StageTest<Clue> { |
| 62 | +
|
| 63 | + @Override |
| 64 | + public List<TestCase<Clue>> generate() { |
| 65 | + return Collections.singletonList( |
| 66 | + new TestCase<Clue>() |
| 67 | + .setInput("Marry\n1\n0\n5\n10") |
| 68 | + .setAttach(new Clue("Marry", 40, 10)) |
| 69 | + ); |
| 70 | + } |
| 71 | +
|
| 72 | + @Override |
| 73 | + public CheckResult check(String reply, Clue clue) { |
| 74 | +
|
| 75 | + String[] lines = reply.trim().split("\n"); |
| 76 | +
|
| 77 | + int length = 9 + clue.count + 1; |
| 78 | +
|
| 79 | + if (lines.length != length) { |
| 80 | + return CheckResult.wrong( |
| 81 | + "You should output " + length + " lines " + |
| 82 | + "(for the count number " + clue.count +").\n" + |
| 83 | + "Lines found: " + lines.length + "\n" + |
| 84 | + "Your output:\n" + |
| 85 | + reply |
| 86 | + ); |
| 87 | + } |
| 88 | +
|
| 89 | + String lineWithName = lines[3].toLowerCase(); |
| 90 | + String name = clue.name.toLowerCase(); |
| 91 | +
|
| 92 | + if (!lineWithName.contains(name)) { |
| 93 | + return CheckResult.wrong( |
| 94 | + "The name was " + clue.name + "\n" + |
| 95 | + "But the 4-th line was:\n" + |
| 96 | + "\"" + lines[3] + "\"\n\n" + |
| 97 | + "4-th line should contain a name of the user" |
| 98 | + ); |
| 99 | + } |
| 100 | +
|
| 101 | + String lineWithAge = lines[6].toLowerCase(); |
| 102 | + String age = Integer.toString(clue.age); |
| 103 | +
|
| 104 | + if (!lineWithAge.contains(age)) { |
| 105 | + return CheckResult.wrong( |
| 106 | + "Can't find a correct age " + |
| 107 | + "in the last line of output! " + |
| 108 | + "Maybe you calculated the age wrong?\n\n" + |
| 109 | + "Your last line: \n" + "\"" + lines[6] + "\"" |
| 110 | + ); |
| 111 | + } |
| 112 | +
|
| 113 | + for (int i = 0; i < clue.count + 1; i++) { |
| 114 | + String numLine = lines[i + 8]; |
| 115 | + String actualNum = i + "!"; |
| 116 | +
|
| 117 | + if (!numLine.equals(actualNum)) { |
| 118 | + return CheckResult.wrong( |
| 119 | + "Expected " + (i+8) + "-th line: \n" + |
| 120 | + "\"" + actualNum + "\"\n" + |
| 121 | + "Your "+ (i+8) + "-th line: \n" + |
| 122 | + "\"" + numLine + "\"" |
| 123 | + ); |
| 124 | + } |
| 125 | + } |
| 126 | +
|
| 127 | + return CheckResult.correct(); |
| 128 | + } |
| 129 | +
|
| 130 | + } |
| 131 | + learner_created: false |
| 132 | +feedback_link: https://hyperskill.org/projects/126/stages/671/implement#comment |
| 133 | +status: Solved |
| 134 | +record: 3 |
0 commit comments