From c38754ccfe3716ebc1d36e111aad08c890552a18 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=A2=D0=B0=D1=82=D1=8C=D1=8F=D0=BD=D0=B0=20=D0=92=D0=B8?= =?UTF-8?q?=D1=85=D1=80=D1=8F=D0=BD=D0=BE=D0=B2=D0=B0?= Date: Mon, 12 Jan 2026 18:04:22 +0700 Subject: [PATCH] =?UTF-8?q?=D0=9F=D1=80=D0=B8=D0=BB=D0=BE=D0=B6=D0=B5?= =?UTF-8?q?=D0=BD=D0=B8=D0=B5=20=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 | 1258 ++++++++++++++++++++++++++++++ .idea/misc.xml | 2 +- src/main/kotlin/Archive.kt | 3 + src/main/kotlin/Main.kt | 132 +++- src/main/kotlin/Menu.kt | 36 + src/main/kotlin/Note.kt | 1 + src/main/kotlin/Screen.kt | 32 + 7 files changed, 1461 insertions(+), 3 deletions(-) create mode 100644 .idea/caches/deviceStreaming.xml create mode 100644 src/main/kotlin/Archive.kt create mode 100644 src/main/kotlin/Menu.kt create mode 100644 src/main/kotlin/Note.kt create mode 100644 src/main/kotlin/Screen.kt diff --git a/.idea/caches/deviceStreaming.xml b/.idea/caches/deviceStreaming.xml new file mode 100644 index 00000000..51d2b618 --- /dev/null +++ b/.idea/caches/deviceStreaming.xml @@ -0,0 +1,1258 @@ + + + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml index 9c8e7400..52b96137 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/Archive.kt b/src/main/kotlin/Archive.kt new file mode 100644 index 00000000..2a368648 --- /dev/null +++ b/src/main/kotlin/Archive.kt @@ -0,0 +1,3 @@ +class Archive(val name: String) { + val notes = mutableListOf() +} \ No newline at end of file diff --git a/src/main/kotlin/Main.kt b/src/main/kotlin/Main.kt index aade54c5..bcb35af3 100644 --- a/src/main/kotlin/Main.kt +++ b/src/main/kotlin/Main.kt @@ -1,3 +1,131 @@ -fun main(args: Array) { - println("Hello World!") +import java.util.Scanner + +val archives = mutableListOf() +val scanner = Scanner(System.`in`) + +fun main() { + val archiveMenu = Menu("Архивы") + + archiveMenu.addOption("Создать архив") { + createArchive() + } + + archiveMenu.addOption("Выбрать архив") { + chooseArchive() + } + + archiveMenu.show() +} + +fun createArchive() { + println("\n=== Создание архива ===") + print("Введите название архива: ") + val name = scanner.nextLine().trim() + + if (name.isEmpty()) { + println("Ошибка: название не может быть пустым") + return + } + + archives.add(Archive(name)) + println("Архив '$name' создан") +} + +fun chooseArchive() { + selectFromList( + title = "Выбор архива", + items = archives, + itemToString = { it.name }, + onSelect = { archive -> + showNotesMenu(archive) + } + ) +} + +fun showNotesMenu(archive: Archive) { + val notesMenu = Menu("Заметки архива: ${archive.name}") + + notesMenu.addOption("Создать заметку") { + createNote(archive) + } + + notesMenu.addOption("Просмотреть заметки") { + chooseNote(archive) + } + + notesMenu.show() +} + +fun createNote(archive: Archive) { + println("\n=== Создание заметки ===") + + print("Введите заголовок заметки: ") + val title = scanner.nextLine().trim() + + if (title.isEmpty()) { + println("Ошибка: заголовок не может быть пустым") + return + } + + print("Введите содержание заметки: ") + val content = scanner.nextLine().trim() + + if (content.isEmpty()) { + println("Ошибка: содержание не может быть пустым") + return + } + + archive.notes.add(Note(title, content)) + println("Заметка '$title' создана") +} + +fun chooseNote(archive: Archive) { + selectFromList( + title = "Выбор заметки", + items = archive.notes, + itemToString = { it.title }, + onSelect = { note -> + showNoteContent(note) + } + ) +} + +fun showNoteContent(note: Note) { + println("\n=== ${note.title} ===") + println(note.content) + println("\nНажмите Enter для возврата...") + scanner.nextLine() +} + +fun selectFromList( + title: String, + items: List, + itemToString: (T) -> String, + onSelect: (T) -> Unit +) { + if (items.isEmpty()) { + println("Список пуст") + return + } + + println("\n=== $title ===") + items.forEachIndexed { index, item -> + println("$index. ${itemToString(item)}") + } + println("${items.size}. Назад") + + print("Выберите пункт: ") + val input = scanner.nextLine() + + if (input == items.size.toString()) { + return + } + + val choice = input.toIntOrNull() + if (choice == null || choice !in items.indices) { + println("Ошибка: введите число от 0 до ${items.size - 1}") + return + } + + onSelect(items[choice]) } \ 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 00000000..c5c6faf3 --- /dev/null +++ b/src/main/kotlin/Menu.kt @@ -0,0 +1,36 @@ +import java.util.Scanner + +class Menu(val title: String) { + private val options = mutableListOf Unit>>() + private val scanner = Scanner(System.`in`) + + fun addOption(name: String, action: () -> Unit) { + options.add(Pair(name, action)) + } + + fun show() { + while (true) { + println("\n=== $title ===") + options.forEachIndexed { index, (name, _) -> + println("$index. $name") + } + println("${options.size}. Выход") + + print("Выберите пункт: ") + val input = scanner.nextLine() + + if (input == options.size.toString()) { + println("Выход...") + break + } + + val choice = input.toIntOrNull() + if (choice == null || choice !in options.indices) { + println("Ошибка: введите число от 0 до ${options.size - 1}") + continue + } + + options[choice].second.invoke() + } + } +} \ 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 00000000..0307e6fe --- /dev/null +++ b/src/main/kotlin/Note.kt @@ -0,0 +1 @@ +class Note(val title: String, val content: String) \ No newline at end of file diff --git a/src/main/kotlin/Screen.kt b/src/main/kotlin/Screen.kt new file mode 100644 index 00000000..9d58f185 --- /dev/null +++ b/src/main/kotlin/Screen.kt @@ -0,0 +1,32 @@ +import java.util.Scanner + +class Screen(val title: String, val options: List Unit>>) { + + private val scanner = Scanner(System.`in`) + + fun show() { + while (true) { + println("\n=== $title ===") + options.forEachIndexed { index, option -> + println("$index. ${option.first}") + } + println("${options.size}. Выход") + + print("Выберите пункт: ") + val input = scanner.nextLine() + + if (input == options.size.toString()) { + println("Выход...") + break + } + + val choice = input.toIntOrNull() + if (choice == null || choice !in options.indices) { + println("Ошибка: введите число от 0 до ${options.size - 1}") + continue + } + + options[choice].second.invoke() + } + } +} \ No newline at end of file