Skip to content

Commit

Permalink
Bump kotlin test framework version + restructure the first project
Browse files Browse the repository at this point in the history
  • Loading branch information
nbirillo committed Dec 12, 2023
1 parent 2571563 commit 101635c
Show file tree
Hide file tree
Showing 48 changed files with 369 additions and 178 deletions.
2 changes: 1 addition & 1 deletion AlmostDone/CompleteTheProject/task-remote-info.yaml
Original file line number Diff line number Diff line change
@@ -1 +1 @@
id: 9116188
id: 819355706
2 changes: 1 addition & 1 deletion Chat/CompleteTheProject/task-remote-info.yaml
Original file line number Diff line number Diff line change
@@ -1 +1 @@
id: 217222142
id: 1922043498
2 changes: 1 addition & 1 deletion Hangman/CompleteTheProject/task-remote-info.yaml
Original file line number Diff line number Diff line change
@@ -1 +1 @@
id: 650289289
id: 1840247486
2 changes: 1 addition & 1 deletion LastPush/CompleteTheProject/task-remote-info.yaml
Original file line number Diff line number Diff line change
@@ -1 +1 @@
id: 716388467
id: 1120394004
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
type: edu
custom_name: Built-in Functions
custom_name: Start the Game
files:
- name: test/Tests.kt
visible: false
Expand Down
43 changes: 7 additions & 36 deletions TheFirstDateWithProgramming/BuiltinFunctions/task.md
Original file line number Diff line number Diff line change
@@ -1,46 +1,17 @@
### Theory
Let's start to implement our **Story twister** project. Let's start from printing an introduction to the user.

Kotlin, like any other programming language,
already has many predefined (**built-in**) functions.
You may have noticed one of them in the previous task – `println`.
It allows you to display the text passed as an _argument_ in the console.
We need an argument in this case so that the function can perform
the _same_ action on _different_ data.
<div class="hint" title="Push me to view how the project will look like after completing all tasks of this project">

For example, if you want to display two words – `One` and `Two` – on different lines,
then in both cases you need to use the same [`println`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.io/println.html#println) function but _with different arguments_:
```kotlin
println("One")
println("Two")
```
The output is:
```text
One
Two
```
![The game's example](../../utils/src/main/resources/images/part1/first.date/game.gif "The game's example")

Kotlin also has another similar function - [`print`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.io/print.html#print).
The only difference from `println` is that it does not wrap text to a new line.
Thus, if we replace the `println` function from the previous example
with the `print` function, we get the following result:

```kotlin
print("One")
print("Two")
```
The output is:
```text
OneTwo
```

It is **important** to note that the text we want to print to the console
must be enclosed in _double quotes_.
___
</div>

### Task

**Description**: print the following text using the `print` or `println` function:
Print the following text using the `print` or `println` function:
```text
Hello! I will ask you several questions.
Please answer all of them and be honest with me!
```

**Note**: to avoid typos just copy the text from here and paste into your code.
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
package jetbrains.kotlin.course.first.date

fun main() {
println("Hello! I will ask you several questions.\n" +
"Please answer all of them and be honest with me!")
println("Hello! I will ask you several questions.")
println("Please answer all of them and be honest with me!")
println("What is TROTEN?")
val firstUserAnswer = readlnOrNull()
println("How did you spend your graduation?")
val secondUserAnswer = readlnOrNull()
println("Why does a spider need eight legs?")
val thirdUserAnswer = readlnOrNull()
println("Now let's have fun!")
println("$firstQuestion\n$firstUserAnswer")
println("$secondQuestion\n$secondUserAnswer")
println("$thirdQuestion\n$thirdUserAnswer")
println(firstQuestion)
println(firstUserAnswer)
println(secondQuestion)
println(secondUserAnswer)
println(thirdQuestion)
println(thirdUserAnswer)
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@ files:
- name: src/main/kotlin/jetbrains/kotlin/course/first/date/Main.kt
visible: true
- name: src/main/kotlin/jetbrains/kotlin/course/first/date/RealQuestions.kt
visible: false
visible: true
feedback_link: https://docs.google.com/forms/d/e/1FAIpQLScylICclQIi9_YDjO7iuyRITDLn0Qgzw_aLxKxiishKAbL0qg/viewform?usp=pp_url&entry.2103429047=Introduction/The+first+day+with+programming/Complete+the+Project
72 changes: 38 additions & 34 deletions TheFirstDateWithProgramming/CompleteTheProject/task.md
Original file line number Diff line number Diff line change
@@ -1,59 +1,63 @@
### Theory

Congratulations, you've almost finished your first project!

<div class="hint" title="Extra theory">

I'll tell you a little trick on how you can write [comments](https://kotlinlang.org/docs/basic-syntax.html#comments)
for other developers (or for yourself) in your code.
To do this, use a double slash at the beginning of the code line:
```kotlin
fun main() {
// My comment, I can write whatever I want here
}
```
Comments are usually left for the most difficult parts of the code.
They make it easier to later understand what the code is doing.

</div>
___

### Task

**Description**: Print the real questions and the user's answers to them.
After answering fake questions that we implemented on the previous steps,
print the text `Now let's have fun!`.
Then print the real questions along with the previous user’s answers.
The real questions are stored in the already **predefined** `firstQuestion`, `secondQuestion`, and `thirdQuestion` variables.
Before the real questions, print the text:
```text
Now let's have fun!
```

_Predefined_ means that you can access these variables
because the course creator put them in the project and added the necessary values.
For example, you can write `println("First question: $firstQuestion")` to print the value from the **predefined** `firstQuestion` variable and an additional text before (or after) it.
For example, you can write `println(firstQuestion)` to print
the value from the **predefined** `firstQuestion` variable.
You can find all these variables in the `RealQuestions.kt` file.

If you have any difficulties, **hints will help you solve this task**.

----

### Hints

<div class="hint" title="What does $ mean?">
<div class="hint" title="Push me to view an example with the first real question">

String literals may contain template expressions – pieces of code that are
evaluated and whose results are concatenated into the string.
[A template expression](https://kotlinlang.org/docs/strings.html#string-templates) starts with a dollar sign (`$`) and consists of either a name or an expression in curly braces.
To print the first **predefined** question from the `firstQuestion` variable and the user answer, you
can use the `println` function from the previous steps:

To insert something into a string, you can use the following construction:
```kotlin
val a = 5
println("a = $a") // a = 5 will be printed
fun main() {
println("Hello! I will ask you several questions.")
println("Please answer all of them and be honest with me!")
println("What is TROTEN?")
val firstUserAnswer = readlnOrNull()
println("How did you spend your graduation?")
val secondUserAnswer = readlnOrNull()
println("Why does a spider need eight legs?")
val thirdUserAnswer = readlnOrNull()
println("Now let's have fun!")
println(firstQuestion)
println(firstUserAnswer)
}
```

</div>

<div class="hint" title="Game's example">
<div class="hint" title="Push me to view the expected state of the game after completing this task">

The game should look like this:

![The game's example](../../utils/src/main/resources/images/part1/first.date/game.gif "The game's example")

</div>

<div class="hint" title="Push me to learn how to combine text and string variables together">

String literals may contain template expressions – pieces of code that are
evaluated and whose results are concatenated into the string.
[A template expression](https://kotlinlang.org/docs/strings.html#string-templates) starts with a dollar sign (`$`) and consists of either a name or an expression in curly braces.

To insert something into a string, you can use the following construction:
```kotlin
val a = 5
println("a = $a") // a = 5 will be printed
```
</div>

5 changes: 2 additions & 3 deletions TheFirstDateWithProgramming/Introduction/task.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,8 @@ Let's go!
### Project description

The project of this lesson is **Story twister**.
The goal of this game is to ask the user several fun questions,
remember the answers, and build a fun story from these answers.
We will replace the real questions with new ones to make the final story ridiculous.
The goal of this game is to ask the user several fake questions,
remember the answers, and then reveal the real questions to build a fun story from these answers.

### Lesson topics

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
type: edu
custom_name: Program entry point
custom_name: First Kotlin program
files:
- name: src/main/kotlin/jetbrains/kotlin/course/first/date/Main.kt
visible: true
Expand Down
31 changes: 8 additions & 23 deletions TheFirstDateWithProgramming/ProgramEntryPoint/task.md
Original file line number Diff line number Diff line change
@@ -1,29 +1,14 @@
### Theory
It's time to write your first program in Kotlin!

Every program in any programming language has an **entry point**.
As a rule, it is a special place in the program that controls everything
that happens around.

In Kotlin, the [entry point](https://kotlinlang.org/docs/basic-syntax.html#program-entry-point) is the special `main` function, which looks like this:
```kotlin
fun main() {
// Some code here
}
```

Everything that happens _inside_ the function (between the curly braces)
will be executed while the program is running.
This function can be placed in _any_ file in your project;
you can even add _several_ `main` functions to one project.
In the latter case, you can choose by yourself which entry point you want to run.
### Task

To `run` a program, you should click on the **green triangle** near the `main` function,
and then the result of the program will be displayed in the _console_ inside the IDE:
Change the output text into `Hello!` and run the program.

![Program entry point and console](../../utils/src/main/resources/images/part1/first.date/entry_point.png "Program entry point and console")
<div class="hint" title="Push me to learn how to run your program">

___
To run your program you need to open the `Main.kt` file and click on the **green triangle** near the `main` function.
Then, the output of the program will be shown in the console:

### Task
![Program entry point and console](../../utils/src/main/resources/images/part1/first.date/run_example.gif "Program entry point and console")

**Description**: change the output text into `Hello!` and run the program.
</div>
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package jetbrains.kotlin.course.first.date

fun main() {
println("Hello! I will ask you several questions.\n" +
"Please answer all of them and be honest with me!")
println("Hello! I will ask you several questions.")
println("Please answer all of them and be honest with me!")
println("What is TROTEN?")
val firstUserAnswer = readlnOrNull()
println("How did you spend your graduation?")
Expand Down
2 changes: 1 addition & 1 deletion TheFirstDateWithProgramming/ReadUserInput/task-info.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
type: edu
custom_name: Read user input
custom_name: Read user input - Practice
files:
- name: test/Tests.kt
visible: false
Expand Down
56 changes: 30 additions & 26 deletions TheFirstDateWithProgramming/ReadUserInput/task.md
Original file line number Diff line number Diff line change
@@ -1,47 +1,51 @@
### Theory

We have previously talked about the _built-in_ functions in Kotlin.
In addition to the already familiar functions for output to the console,
Kotlin has the [`readlnOrNull`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.io/readln-or-null.html) function, which reads the values entered by the user and stores them in a variable:

```kotlin
val myValue = readlnOrNull()
// The myValue variable stores the user's input
```

For example, in our **Story twister** project,
we need to ask the user a question and then remember their answer.
That is exactly what the `readlnOrNull` function is for.
The function tells the program to stop and wait for
the user to enter some value into the console; then it allows the program to receive the value and, for example, write it into a variable.

It is important that in this case you **cannot** write:
```kotlin
val myValue: String = readlnOrNull()
// The myValue variable stores the user's input
```
It is connected to the null safety in Kotlin, we will consider it later, but if you are interested in this topic, you can read more in the [documentation](https://kotlinlang.org/docs/null-safety.html).
___
In this task you will ask the user three questions and save their answers.

### Task

**Description**: ask the user three questions and add the answers
Ask the user three questions and add the answers
to the _firstUserAnswer_, _secondUserAnswer_, and _thirdUserAnswer_ variables respectively.
The questions are:

```text
What is TROTEN?
How did you spend your graduation?
Why does a spider need eight legs?
```

You must ask questions and record answers sequentially,
i.e. first ask the first question (_print_ it to console),
then record the answer in the _firstUserAnswer_ variable.
Then do the same with the second question and the _secondUserAnswer_ variable,
and the last question and the last _thirdUserAnswer_ variable.

If you have any difficulties, **hints will help you solve this task**.

----

### Hints

<div class="hint" title="Clarification">
<div class="hint" title="Push me to view an example with the first question">

To print a question you can use the `println` function from the previous steps.
Then, no read the user input, you can use the `readlnOrNull` function:

```kotlin
fun main() {
println("Hello! I will ask you several questions.")
println("Please answer all of them and be honest with me!")
println("What is TROTEN?")
val firstUserAnswer = readlnOrNull()
// You need to ask two others questions bellow
val secondUserAnswer = ""
val thirdUserAnswer = ""
}
```

</div>

<div class="hint" title="Push me to view the expected state of the application after completing this task">

As a result, the user's interaction with the game will look like this:

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package jetbrains.kotlin.course.first.date

fun main() {
println("Hello! I will ask you several questions.\n" +
"Please answer all of them and be honest with me!")
println("Hello! I will ask you several questions.")
println("Please answer all of them and be honest with me!")
val firstUserAnswer = ""
val secondUserAnswer = ""
val thirdUserAnswer = ""
Expand Down
1 change: 1 addition & 0 deletions TheFirstDateWithProgramming/Variables/task-info.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
type: edu
custom_name: Variables - Practice
files:
- name: test/Tests.kt
visible: false
Expand Down
Loading

0 comments on commit 101635c

Please sign in to comment.