Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions src/main/kotlin/stage_1/stage_1.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,19 @@ import java.io.File

fun main() {

val dictionary = mutableListOf<Word>()
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)

}
}

data class Word(
val original:String,
val translate:String
)
52 changes: 52 additions & 0 deletions src/main/kotlin/stage_3/stage_3_1.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package stage_3

import stage_1.Word
import java.io.File


fun main() {

val dictionary = mutableListOf<Word>()
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 //Счётчик для выученных слов

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

это не просто переменная, а поле класса Word. такая же часть сущности, как и оригинал и перевод


/* val dictionary2 = dictionary.filter {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

какая функция этого комментария?

println("Как переводится слово: ${it.original}")
readlnOrNull() ==it.translate
}*/
val dictionary2 = dictionary
for (i in dictionary2){
println("Как переводится слово: ${i.original}")

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

этого задания нет в описании этапа

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

и мы используем только 1 словарь. это то, что получено из файла

val userInputAnswer = readLine()
if(userInputAnswer == i.translate){
correctAnswersCount += 1
}
}


val quantityWords = dictionary.size //Количество слов в словаре
val percentageRatio = (correctAnswersCount.toFloat() / quantityWords.toFloat()) * 100

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

33 и 34 лучше перенести туда , где они используются. там же добывать правильные слова. нужен порядок в коде. чтобы ничего лишнего не было за пределами when/цикла, если это не переиспользуется еще где-то




do{

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

тут достаточно классического цикла while true

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
)
7 changes: 4 additions & 3 deletions words.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
hello привет
dog собака
cat кошка
hello|привет
dog|собака
cat|кошка
thank you|спасибо