-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Bump kotlin test framework version + restructure the first project
- Loading branch information
Showing
48 changed files
with
369 additions
and
178 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
id: 9116188 | ||
id: 819355706 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
id: 217222142 | ||
id: 1922043498 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
id: 650289289 | ||
id: 1840247486 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
id: 716388467 | ||
id: 1120394004 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
13 changes: 8 additions & 5 deletions
13
...Programming/CompleteTheProject/src/main/kotlin/jetbrains/kotlin/course/first/date/Main.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
4 changes: 2 additions & 2 deletions
4
...eWithProgramming/ReadUserInput/src/main/kotlin/jetbrains/kotlin/course/first/date/Main.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
...tDateWithProgramming/Variables/src/main/kotlin/jetbrains/kotlin/course/first/date/Main.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
|
Oops, something went wrong.