Skip to content

Commit 35eb6a0

Browse files
committed
simple kotlin app
1 parent a9754e2 commit 35eb6a0

26 files changed

+1462
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
type: edu
2+
files:
3+
- name: src/bot/SimpleBot.kt
4+
visible: true
5+
text: |
6+
package bot
7+
8+
fun main() {
9+
// write your code here
10+
}
11+
learner_created: false
12+
- name: test/ChattyBotTest.java
13+
visible: false
14+
text: |
15+
import org.hyperskill.hstest.stage.StageTest;
16+
import org.hyperskill.hstest.testcase.CheckResult;
17+
import org.hyperskill.hstest.testcase.TestCase;
18+
19+
import java.util.Collections;
20+
import java.util.List;
21+
22+
23+
public class ChattyBotTest extends StageTest<Object> {
24+
25+
@Override
26+
public List<TestCase<Object>> generate() {
27+
return Collections.singletonList(
28+
new TestCase<>()
29+
);
30+
}
31+
32+
@Override
33+
public CheckResult check(String reply, Object clue) {
34+
35+
String[] lines = reply.trim().split("\n");
36+
37+
if (lines.length != 2) {
38+
return CheckResult.wrong(
39+
"You should output exactly 2 lines!\n" +
40+
"Lines found: " + lines.length
41+
);
42+
}
43+
44+
String secondLine = lines[1];
45+
46+
if (!secondLine.matches(".*\\d.*")) {
47+
return CheckResult.wrong(
48+
"The second line should contain a year!\n" +
49+
"Your second line: \"" + secondLine + "\""
50+
);
51+
}
52+
53+
return CheckResult.correct();
54+
}
55+
}
56+
learner_created: false
57+
feedback_link: https://hyperskill.org/projects/126/stages/668/implement#comment
58+
status: Solved
59+
record: 5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
id: 10770
2+
update_date: "Thu, 08 Dec 2022 23:08:37 UTC"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<h5 id="description" style="text-align: center;">Description</h5>
2+
<p>Digital personal assistants help people to drive cars, plan their day, buy something online. In a sense, they are simplified versions of artificial intelligence with whom you can talk.</p>
3+
<p>In this project, you will develop step by step a simple bot that will help you study programming.</p>
4+
<h5 id="objective" style="text-align: center;">Objective</h5>
5+
<p>For the first stage, you will write a bot who displays a greeting, its name, and the date of its creation. First impressions count!</p>
6+
<p>Your program should print the following lines:</p>
7+
<pre><code class="language-no-highlight">Hello! My name is {botName}.
8+
I was created in {birthYear}.</code></pre>
9+
<p>Instead of <code class="java">{botName}</code>, print any name you choose and replace <code class="java">{birthYear}</code> with the current year (four digits).</p>
10+
<h5 id="example" style="text-align: center;">Example</h5>
11+
<p>Output:</p>
12+
<pre><code class="language-no-highlight">Hello! My name is Aid.
13+
I was created in 2020.</code></pre>
14+
<p>You can change the text if you want but print exactly two lines.</p>
15+
<p>Next, we will use <strong>Aid</strong> and <strong>2020</strong> as your bot's name and its birth year, but you can change it if you need to.</p>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
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+
// reading all remainders
25+
26+
println("Your age is {yourAge}; that's a good time to start programming!")
27+
}
28+
learner_created: false
29+
- name: test/ChattyBotTest.java
30+
visible: false
31+
text: |
32+
import org.hyperskill.hstest.stage.StageTest;
33+
import org.hyperskill.hstest.testcase.CheckResult;
34+
import org.hyperskill.hstest.testcase.TestCase;
35+
36+
import java.util.Arrays;
37+
import java.util.List;
38+
39+
40+
class Clue {
41+
int age;
42+
String name;
43+
44+
Clue(String name, int age) {
45+
this.age = age;
46+
this.name = name;
47+
}
48+
}
49+
50+
51+
public class ChattyBotTest extends StageTest<Clue> {
52+
53+
@Override
54+
public List<TestCase<Clue>> generate() {
55+
return Arrays.asList(
56+
new TestCase<Clue>()
57+
.setInput("John\n1\n2\n1")
58+
.setAttach(new Clue("John", 22)),
59+
60+
new TestCase<Clue>()
61+
.setInput("Nick\n2\n0\n0")
62+
.setAttach(new Clue("Nick", 35))
63+
);
64+
}
65+
66+
@Override
67+
public CheckResult check(String reply, Clue clue) {
68+
69+
String[] lines = reply.trim().split("\n");
70+
71+
if (lines.length != 7) {
72+
return CheckResult.wrong(
73+
"You should output 7 lines. Lines found: " + lines.length + "\n" +
74+
"Your output:\n" +
75+
reply
76+
);
77+
}
78+
79+
String lineWithName = lines[3].toLowerCase();
80+
String name = clue.name.toLowerCase();
81+
82+
if (!lineWithName.contains(name)) {
83+
return CheckResult.wrong(
84+
"The name was " + clue.name + "\n" +
85+
"But the 4-th line was:\n" +
86+
"\"" + lines[3] + "\"\n\n" +
87+
"4-th line should contain a name of the user"
88+
);
89+
}
90+
91+
String lineWithAge = lines[6].toLowerCase();
92+
String age = Integer.toString(clue.age);
93+
94+
if (!lineWithAge.contains(age)) {
95+
return CheckResult.wrong(
96+
"Can't find a correct age " +
97+
"in the last line of output! " +
98+
"Maybe you calculated the age wrong?\n\n" +
99+
"Your last line: \n" + "\"" + lines[6] + "\""
100+
);
101+
}
102+
103+
return CheckResult.correct();
104+
}
105+
106+
}
107+
learner_created: false
108+
feedback_link: https://hyperskill.org/projects/126/stages/670/implement#comment
109+
status: Solved
110+
record: 2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
id: 10772
2+
update_date: "Fri, 09 Dec 2022 13:31:35 UTC"
+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<h5 id="description" style="text-align: center;">Description</h5>
2+
<p>Keep improving your bot by developing new skills for it. We suggest a simple guessing game that will predict the age of a user.</p>
3+
<p>It's based on a simple math trick. First, take a look at this formula:</p>
4+
<pre><code class="java">age = (remainder3 * 70 + remainder5 * 21 + remainder7 * 15) % 105</code></pre>
5+
<p>The numbers <code class="java">remainder3</code>, <code class="java">remainder5</code>, and <code class="java">remainder7</code> are the remainders of division by 3, 5, and 7 respectively.</p>
6+
<p>It turns out that for each number ranging from <em>0</em> to <em>104,</em> the calculation will result in the number itself. This perfectly fits the ordinary age range, doesn't it? Ask the user for the remainders and use them to guess the age!</p>
7+
<h5 id="objective" style="text-align: center;">Objective</h5>
8+
<p>In this stage, you will introduce yourself to the bot. It will greet you by your name and then try to guess your age using arithmetic operations.</p>
9+
<p>Your program should print the following lines:</p>
10+
<pre><code class="language-no-highlight">Hello! My name is Aid.
11+
I was created in 2020.
12+
Please, remind me your name.
13+
What a great name you have, Max!
14+
Let me guess your age.
15+
Enter remainders of dividing your age by 3, 5 and 7.
16+
Your age is {yourAge}; that's a good time to start programming!</code></pre>
17+
<p>Read three numbers from the standard input. Assume that all the numbers will be given on separate lines.</p>
18+
<p>Instead of <code class="java">{yourAge}</code>, the bot will print the age determined according to the special formula discussed above.</p>
19+
<h5 id="example" style="text-align: center;">Example</h5>
20+
<p>The greater-than symbol followed by a space (<code class="java">&gt; </code>) represents the user input. Note that it's not part of the input.</p>
21+
<p><strong>Example 1:</strong> <em>a dialogue with the bot</em></p>
22+
<pre><code class="language-no-highlight">Hello! My name is Aid.
23+
I was created in 2020.
24+
Please, remind me your name.
25+
&gt; Max
26+
What a great name you have, Max!
27+
Let me guess your age.
28+
Enter remainders of dividing your age by 3, 5 and 7.
29+
&gt; 1
30+
&gt; 2
31+
&gt; 1
32+
Your age is 22; that's a good time to start programming!</code></pre>
33+
<p>Use the provided template to simplify your work. You can change the text but not the number of printed lines.</p>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,134 @@
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
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
id: 10773
2+
update_date: "Sun, 11 Dec 2022 16:21:07 UTC"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<h5 id="description" style="text-align: center;">Description</h5>
2+
<p>Now you will teach your bot to count. It's going to become an expert in numbers!</p>
3+
<h5 id="objective" style="text-align: center;">Objective</h5>
4+
<p>In this stage, you will program the bot to count from 0 to any positive number users enter.</p>
5+
<h5 id="example" style="text-align: center;">Example</h5>
6+
<p>The greater-than symbol followed by a space (<code class="java">&gt; </code>) represents the user input. Note that it's not part of the input.</p>
7+
<p><strong>Example 1:</strong> <em>a dialogue with the new version of the bot</em></p>
8+
<pre><code class="language-no-highlight">Hello! My name is Aid.
9+
I was created in 2020.
10+
Please, remind me your name.
11+
&gt; Max
12+
What a great name you have, Max!
13+
Let me guess your age.
14+
Enter remainders of dividing your age by 3, 5 and 7.
15+
&gt; 1
16+
&gt; 2
17+
&gt; 1
18+
Your age is 22; that's a good time to start programming!
19+
Now I will prove to you that I can count to any number you want.
20+
&gt; 5
21+
0!
22+
1!
23+
2!
24+
3!
25+
4!
26+
5!
27+
Completed, have a nice day!</code></pre>
28+
<p><strong>Note: </strong>each number starts with a new line, and after a number, the bot should print the exclamation mark.</p>
29+
<p>Use the provided template to simplify your work. You can change the text if you want, but be especially careful when counting numbers.</p>

0 commit comments

Comments
 (0)