From 5a387b79ccea4010773c74196f686b4c9d450d98 Mon Sep 17 00:00:00 2001 From: maksim Date: Wed, 22 Jul 2026 17:49:23 +0300 Subject: [PATCH 1/2] =?UTF-8?q?=D0=97=D0=B0=D0=BC=D0=B5=D1=82=D0=BA=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .idea/markdown.xml | 8 ++++++++ .idea/misc.xml | 2 +- src/main/kotlin/Main.kt | 6 ++++-- 3 files changed, 13 insertions(+), 3 deletions(-) create mode 100644 .idea/markdown.xml diff --git a/.idea/markdown.xml b/.idea/markdown.xml new file mode 100644 index 000000000..c61ea3346 --- /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 9c8e74009..6ea4ea072 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -1,6 +1,6 @@ - + \ No newline at end of file diff --git a/src/main/kotlin/Main.kt b/src/main/kotlin/Main.kt index aade54c57..74458cf3f 100644 --- a/src/main/kotlin/Main.kt +++ b/src/main/kotlin/Main.kt @@ -1,3 +1,5 @@ -fun main(args: Array) { - println("Hello World!") +fun main() { + val archives = mutableListOf() + + ArchiveMenu(archives).show() } \ No newline at end of file From 3570118e1bf4d3190c16dc533941c67593f3bec8 Mon Sep 17 00:00:00 2001 From: maksim Date: Wed, 22 Jul 2026 17:50:40 +0300 Subject: [PATCH 2/2] =?UTF-8?q?=D0=97=D0=B0=D0=BC=D0=B5=D1=82=D0=BA=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .idea/caches/deviceStreaming.xml | 2109 ++++++++++++++++++++++++++++++ src/main/kotlin/Archive.kt | 4 + src/main/kotlin/ArchiveMenu.kt | 50 + src/main/kotlin/NoteMenu.kt | 72 + src/main/kotlin/menu.kt | 33 + src/main/kotlin/note.kt | 4 + 6 files changed, 2272 insertions(+) create mode 100644 .idea/caches/deviceStreaming.xml create mode 100644 src/main/kotlin/Archive.kt create mode 100644 src/main/kotlin/ArchiveMenu.kt create mode 100644 src/main/kotlin/NoteMenu.kt create mode 100644 src/main/kotlin/menu.kt create mode 100644 src/main/kotlin/note.kt diff --git a/.idea/caches/deviceStreaming.xml b/.idea/caches/deviceStreaming.xml new file mode 100644 index 000000000..cdd61d88a --- /dev/null +++ b/.idea/caches/deviceStreaming.xml @@ -0,0 +1,2109 @@ + + + + + + \ No newline at end of file diff --git a/src/main/kotlin/Archive.kt b/src/main/kotlin/Archive.kt new file mode 100644 index 000000000..b25dcf675 --- /dev/null +++ b/src/main/kotlin/Archive.kt @@ -0,0 +1,4 @@ +data class Archive( + val name: String, + val notes: MutableList = mutableListOf() +) \ No newline at end of file diff --git a/src/main/kotlin/ArchiveMenu.kt b/src/main/kotlin/ArchiveMenu.kt new file mode 100644 index 000000000..6c3b6fceb --- /dev/null +++ b/src/main/kotlin/ArchiveMenu.kt @@ -0,0 +1,50 @@ +class ArchiveMenu( + private val archives: MutableList +) { + + fun show() { + while (true) { + val items = mutableListOf("Создать архив") + + archives.forEach { archive -> + items.add(archive.name) + } + + items.add("Выход") + + val menu = Menu( + title = "Список архивов:", + items = items + ) + + when (val choice = menu.show()) { + 0 -> createArchive() + + items.lastIndex -> { + println("Программа завершена.") + return + } + + else -> { + val archive = archives[choice - 1] + NoteMenu(archive).show() + } + } + } + } + + private fun createArchive() { + println() + print("Введите название архива: ") + + val name = readln().trim() + + if (name.isEmpty()) { + println("Название архива не может быть пустым.") + return + } + + archives.add(Archive(name)) + println("Архив «$name» создан.") + } +} \ No newline at end of file diff --git a/src/main/kotlin/NoteMenu.kt b/src/main/kotlin/NoteMenu.kt new file mode 100644 index 000000000..8a1ac325f --- /dev/null +++ b/src/main/kotlin/NoteMenu.kt @@ -0,0 +1,72 @@ +class NoteMenu( + private val archive: Archive +) { + + fun show() { + while (true) { + val items = mutableListOf("Создать заметку") + + archive.notes.forEach { note -> + items.add(note.name) + } + + items.add("Назад") + + val menu = Menu( + title = "Заметки архива «${archive.name}»:", + items = items + ) + + when (val choice = menu.show()) { + 0 -> createNote() + + items.lastIndex -> return + + else -> { + val note = archive.notes[choice - 1] + showNote(note) + } + } + } + } + + private fun createNote() { + println() + print("Введите название заметки: ") + + val name = readln().trim() + + if (name.isEmpty()) { + println("Название заметки не может быть пустым.") + return + } + + print("Введите текст заметки: ") + + val content = readln().trim() + + if (content.isEmpty()) { + println("Текст заметки не может быть пустым.") + return + } + + archive.notes.add( + Note( + name = name, + content = content + ) + ) + + println("Заметка «$name» создана.") + } + + private fun showNote(note: Note) { + println() + println("Заметка: ${note.name}") + println("--------------------") + println(note.content) + println("--------------------") + println("Нажмите Enter, чтобы вернуться назад.") + readln() + } +} \ No newline at end of file diff --git a/src/main/kotlin/menu.kt b/src/main/kotlin/menu.kt new file mode 100644 index 000000000..473a88d9a --- /dev/null +++ b/src/main/kotlin/menu.kt @@ -0,0 +1,33 @@ +class Menu( + private val title: String, + private val items: MutableList +) { + + fun show(): Int { + while (true) { + println() + println(title) + + items.forEachIndexed { index, item -> + println("$index. $item") + } + + print("Выберите пункт: ") + + val input = readln() + val choice = input.toIntOrNull() + + if (choice == null) { + println("Ошибка: введите номер пункта цифрой.") + continue + } + + if (choice !in items.indices) { + println("Ошибка: пункта с номером $choice нет.") + continue + } + + return choice + } + } +} \ No newline at end of file diff --git a/src/main/kotlin/note.kt b/src/main/kotlin/note.kt new file mode 100644 index 000000000..1a18993fa --- /dev/null +++ b/src/main/kotlin/note.kt @@ -0,0 +1,4 @@ +data class Note( + val name: String, + val content: String +) \ No newline at end of file