From f762e092c1574cb82e5ff1979269f9f1eb0b1d6e Mon Sep 17 00:00:00 2001 From: Sergei Safonov Date: Tue, 14 Feb 2023 11:24:15 +0100 Subject: [PATCH 1/3] Stage-2 data class --- src/main/kotlin/stage_1/stage_1.kt | 14 +++++++++++--- words.txt | 7 ++++--- 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/src/main/kotlin/stage_1/stage_1.kt b/src/main/kotlin/stage_1/stage_1.kt index 63777b3..a9660b0 100644 --- a/src/main/kotlin/stage_1/stage_1.kt +++ b/src/main/kotlin/stage_1/stage_1.kt @@ -4,10 +4,18 @@ import java.io.File fun main() { + val dictionary = mutableListOf() val wordsFile: File = File("words.txt") - val wordsList = wordsFile.readLines().toMutableList() + val wordsList = wordsFile.readLines() for(i in wordsList){ - println(i) + val line = i.split("|") + val word = Word(original = line[0], translate = line[1]) + dictionary.add(word) } + println(dictionary) +} -} \ No newline at end of file +data class Word( + val original:String, + val translate:String +) \ No newline at end of file diff --git a/words.txt b/words.txt index 832e808..5ec317e 100644 --- a/words.txt +++ b/words.txt @@ -1,3 +1,4 @@ -hello привет -dog собака -cat кошка \ No newline at end of file +hello|привет +dog|собака +cat|кошка +thank you|спасибо From 3dc3fa21aaa8308013314795c6ef6713e33110ec Mon Sep 17 00:00:00 2001 From: Sergei Safonov Date: Tue, 21 Feb 2023 01:55:49 +0100 Subject: [PATCH 2/3] Stage-3 --- src/main/kotlin/stage_3/stage_3_1.kt | 52 ++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 src/main/kotlin/stage_3/stage_3_1.kt diff --git a/src/main/kotlin/stage_3/stage_3_1.kt b/src/main/kotlin/stage_3/stage_3_1.kt new file mode 100644 index 0000000..96b38eb --- /dev/null +++ b/src/main/kotlin/stage_3/stage_3_1.kt @@ -0,0 +1,52 @@ +package stage_3 + +import stage_1.Word +import java.io.File + + +fun main() { + + val dictionary = mutableListOf() + val wordsFile: File = File("words.txt") + val wordsList = wordsFile.readLines() + for(i in wordsList){ + val line = i.split("|") + val word = Word(original = line[0], translate = line[1]) + dictionary.add(word) + } + var correctAnswersCount = 0 //Счётчик для выученных слов + + /* val dictionary2 = dictionary.filter { + println("Как переводится слово: ${it.original}") + readlnOrNull() ==it.translate + }*/ + val dictionary2 = dictionary + for (i in dictionary2){ + println("Как переводится слово: ${i.original}") + val userInputAnswer = readLine() + if(userInputAnswer == i.translate){ + correctAnswersCount += 1 + } + } + + + val quantityWords = dictionary.size //Количество слов в словаре + val percentageRatio = (correctAnswersCount.toFloat() / quantityWords.toFloat()) * 100 + + + + do{ + println("Меню: 1- Учить слова, 2 - Статистика, 0 - Выход") + println("Выберите нужный пункт меню") + val userInput = readLine()!!.toInt() + when(userInput){ + 2 -> println("Количество слов в словаре: $quantityWords\nВыучено слов $correctAnswersCount из $quantityWords | $percentageRatio%") + 0 -> break + else -> println("Такого пункта меню не существует, попробуйте ещё раз") + } + }while(true) +} +data class Word( + val original:String, + val translate:String +) \ No newline at end of file From ab0829428670a96ef47d32144f3a69612c93290b Mon Sep 17 00:00:00 2001 From: Sergei Safonov Date: Tue, 21 Feb 2023 01:59:16 +0100 Subject: [PATCH 3/3] Stage-1 --- src/main/kotlin/stage_1/stage_1.kt | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/kotlin/stage_1/stage_1.kt b/src/main/kotlin/stage_1/stage_1.kt index a9660b0..930b745 100644 --- a/src/main/kotlin/stage_1/stage_1.kt +++ b/src/main/kotlin/stage_1/stage_1.kt @@ -13,6 +13,7 @@ fun main() { dictionary.add(word) } println(dictionary) + } data class Word(