From b177cf23636ce4121efbd0a5490fe7d4c1c62742 Mon Sep 17 00:00:00 2001 From: Timur Date: Fri, 13 Mar 2026 17:48:35 +0300 Subject: [PATCH 1/2] Commit Main.kt --- .idea/caches/deviceStreaming.xml | 1842 ++++++++++++++++++++++++++++++ .idea/discord.xml | 14 + .idea/markdown.xml | 8 + .idea/misc.xml | 3 +- src/main/kotlin/Main.kt | 76 +- 5 files changed, 1939 insertions(+), 4 deletions(-) create mode 100644 .idea/caches/deviceStreaming.xml create mode 100644 .idea/discord.xml create mode 100644 .idea/markdown.xml diff --git a/.idea/caches/deviceStreaming.xml b/.idea/caches/deviceStreaming.xml new file mode 100644 index 00000000..8a009bb8 --- /dev/null +++ b/.idea/caches/deviceStreaming.xml @@ -0,0 +1,1842 @@ + + + + + + \ No newline at end of file diff --git a/.idea/discord.xml b/.idea/discord.xml new file mode 100644 index 00000000..104c42f5 --- /dev/null +++ b/.idea/discord.xml @@ -0,0 +1,14 @@ + + + + + \ No newline at end of file diff --git a/.idea/markdown.xml b/.idea/markdown.xml new file mode 100644 index 00000000..c61ea334 --- /dev/null +++ b/.idea/markdown.xml @@ -0,0 +1,8 @@ + + + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml index 9c8e7400..7ff9e338 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -1,6 +1,5 @@ - - + \ No newline at end of file diff --git a/src/main/kotlin/Main.kt b/src/main/kotlin/Main.kt index aade54c5..5345803e 100644 --- a/src/main/kotlin/Main.kt +++ b/src/main/kotlin/Main.kt @@ -1,3 +1,75 @@ +data class Note(val title: String, val text: String) +data class Archive (val name: String, val notes: MutableList = mutableListOf()) +val archives = mutableListOf() + fun main(args: Array) { - println("Hello World!") -} \ No newline at end of file + archiveMenu() +} + +fun archiveMenu() { + while (true) { + println("\nСписок архивов:") + println("0. Создать архив") + archives.forEachIndexed { i, archive -> + println("${i + 1}. ${archive.name}") + } + println("${archives.size + 1}. Выход") + + val input = readlnOrNull()?.toIntOrNull() + when { + input == 0 -> createArchive() + input != null && input in 1..archives.size -> noteMenu(archives[input - 1]) + input == archives.size + 1 -> return + else -> println("Некорректный ввод") + } + } +} + +fun createArchive() { + println("Введите название архива:") + val name = readlnOrNull()?.takeIf { it.isNotBlank() } ?: run { + println("Название не может быть пустым") + return + } + archives.add(Archive(name)) + println("Архив '$name' создан") +} +fun createNote(archive: Archive) { + println("Введите заголовок заметки:") + val title = readlnOrNull()?.takeIf { it.isNotBlank() } ?: run { + println("Заголовок не может быть пустым") + return + } + println("Введите текст заметки:") + val text = readlnOrNull()?.takeIf { it.isNotBlank() } ?: run { + println("Текст не может быть пустым") + return + } + archive.notes.add(Note(title, text)) + println("Заметка '$title' добавлена") +} +fun noteMenu(archive: Archive) { + while (true) { + println("\nАрхив: ${archive.name}") + println("0. Создать заметку") + archive.notes.forEachIndexed { i, note -> + println("${i + 1}. ${note.title}") + } + println("${archive.notes.size + 1}. Назад") + + val input = readlnOrNull()?.toIntOrNull() + when { + input == 0 -> createNote(archive) + input != null && input in 1..archive.notes.size -> showNote(archive.notes[input - 1]) + input == archive.notes.size + 1 -> return + else -> println("Некорректный ввод") + } + } +} +fun showNote(note: Note) { + println("\n=== ${note.title} ===") + println(note.text) + println("\nНажмите Enter для возврата") + readlnOrNull() +} + From 1ebe707334fa336079770452380da681ccf33bcd Mon Sep 17 00:00:00 2001 From: Timur Date: Fri, 13 Mar 2026 23:45:05 +0300 Subject: [PATCH 2/2] new commit divided in 3 files. --- src/main/kotlin/Main.kt | 68 +------------------------------ src/main/kotlin/dataModels.kt | 2 + src/main/kotlin/menuAndArchive.kt | 66 ++++++++++++++++++++++++++++++ 3 files changed, 69 insertions(+), 67 deletions(-) create mode 100644 src/main/kotlin/dataModels.kt create mode 100644 src/main/kotlin/menuAndArchive.kt diff --git a/src/main/kotlin/Main.kt b/src/main/kotlin/Main.kt index 5345803e..b836d194 100644 --- a/src/main/kotlin/Main.kt +++ b/src/main/kotlin/Main.kt @@ -1,75 +1,9 @@ -data class Note(val title: String, val text: String) -data class Archive (val name: String, val notes: MutableList = mutableListOf()) + val archives = mutableListOf() fun main(args: Array) { archiveMenu() } -fun archiveMenu() { - while (true) { - println("\nСписок архивов:") - println("0. Создать архив") - archives.forEachIndexed { i, archive -> - println("${i + 1}. ${archive.name}") - } - println("${archives.size + 1}. Выход") - - val input = readlnOrNull()?.toIntOrNull() - when { - input == 0 -> createArchive() - input != null && input in 1..archives.size -> noteMenu(archives[input - 1]) - input == archives.size + 1 -> return - else -> println("Некорректный ввод") - } - } -} - -fun createArchive() { - println("Введите название архива:") - val name = readlnOrNull()?.takeIf { it.isNotBlank() } ?: run { - println("Название не может быть пустым") - return - } - archives.add(Archive(name)) - println("Архив '$name' создан") -} -fun createNote(archive: Archive) { - println("Введите заголовок заметки:") - val title = readlnOrNull()?.takeIf { it.isNotBlank() } ?: run { - println("Заголовок не может быть пустым") - return - } - println("Введите текст заметки:") - val text = readlnOrNull()?.takeIf { it.isNotBlank() } ?: run { - println("Текст не может быть пустым") - return - } - archive.notes.add(Note(title, text)) - println("Заметка '$title' добавлена") -} -fun noteMenu(archive: Archive) { - while (true) { - println("\nАрхив: ${archive.name}") - println("0. Создать заметку") - archive.notes.forEachIndexed { i, note -> - println("${i + 1}. ${note.title}") - } - println("${archive.notes.size + 1}. Назад") - val input = readlnOrNull()?.toIntOrNull() - when { - input == 0 -> createNote(archive) - input != null && input in 1..archive.notes.size -> showNote(archive.notes[input - 1]) - input == archive.notes.size + 1 -> return - else -> println("Некорректный ввод") - } - } -} -fun showNote(note: Note) { - println("\n=== ${note.title} ===") - println(note.text) - println("\nНажмите Enter для возврата") - readlnOrNull() -} diff --git a/src/main/kotlin/dataModels.kt b/src/main/kotlin/dataModels.kt new file mode 100644 index 00000000..be33ce25 --- /dev/null +++ b/src/main/kotlin/dataModels.kt @@ -0,0 +1,2 @@ +data class Note(val title: String, val text: String) +data class Archive (val name: String, val notes: MutableList = mutableListOf()) \ No newline at end of file diff --git a/src/main/kotlin/menuAndArchive.kt b/src/main/kotlin/menuAndArchive.kt new file mode 100644 index 00000000..b607b7c1 --- /dev/null +++ b/src/main/kotlin/menuAndArchive.kt @@ -0,0 +1,66 @@ +fun archiveMenu() { + while (true) { + println("\nСписок архивов:") + println("0. Создать архив") + archives.forEachIndexed { i, archive -> + println("${i + 1}. ${archive.name}") + } + println("${archives.size + 1}. Выход") + + val input = readlnOrNull()?.toIntOrNull() + when { + input == 0 -> createArchive() + input != null && input in 1..archives.size -> noteMenu(archives[input - 1]) + input == archives.size + 1 -> return + else -> println("Некорректный ввод") + } + } +} + +fun createArchive() { + println("Введите название архива:") + val name = readlnOrNull()?.takeIf { it.isNotBlank() } ?: run { + println("Название не может быть пустым") + return + } + archives.add(Archive(name)) + println("Архив '$name' создан") +} +fun createNote(archive: Archive) { + println("Введите заголовок заметки:") + val title = readlnOrNull()?.takeIf { it.isNotBlank() } ?: run { + println("Заголовок не может быть пустым") + return + } + println("Введите текст заметки:") + val text = readlnOrNull()?.takeIf { it.isNotBlank() } ?: run { + println("Текст не может быть пустым") + return + } + archive.notes.add(Note(title, text)) + println("Заметка '$title' добавлена") +} +fun noteMenu(archive: Archive) { + while (true) { + println("\nАрхив: ${archive.name}") + println("0. Создать заметку") + archive.notes.forEachIndexed { i, note -> + println("${i + 1}. ${note.title}") + } + println("${archive.notes.size + 1}. Назад") + + val input = readlnOrNull()?.toIntOrNull() + when { + input == 0 -> createNote(archive) + input != null && input in 1..archive.notes.size -> showNote(archive.notes[input - 1]) + input == archive.notes.size + 1 -> return + else -> println("Некорректный ввод") + } + } +} +fun showNote(note: Note) { + println("\n=== ${note.title} ===") + println(note.text) + println("\nНажмите Enter для возврата") + readlnOrNull() +} \ No newline at end of file