From 9b3c059637f2671c157d6ad0be19adfd0f69ee10 Mon Sep 17 00:00:00 2001 From: Sergey Andreev Date: Sat, 24 May 2025 14:20:13 +0300 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=D1=80=D0=B0=D0=B1=D0=BE=D1=82=D0=B0=D0=B5?= =?UTF-8?q?=D1=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .idea/caches/deviceStreaming.xml | 615 +++++++++++++++++++++++++++++++ .idea/misc.xml | 2 +- src/main/kotlin/Archive.kt | 40 ++ src/main/kotlin/Main.kt | 7 +- src/main/kotlin/MenuManager.kt | 27 ++ src/main/kotlin/Note.kt | 8 + src/main/kotlin/NotesApp.kt | 43 +++ 7 files changed, 738 insertions(+), 4 deletions(-) create mode 100644 .idea/caches/deviceStreaming.xml create mode 100644 src/main/kotlin/Archive.kt create mode 100644 src/main/kotlin/MenuManager.kt create mode 100644 src/main/kotlin/Note.kt create mode 100644 src/main/kotlin/NotesApp.kt diff --git a/.idea/caches/deviceStreaming.xml b/.idea/caches/deviceStreaming.xml new file mode 100644 index 00000000..a55c3244 --- /dev/null +++ b/.idea/caches/deviceStreaming.xml @@ -0,0 +1,615 @@ + + + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml index 9c8e7400..1945ce5f 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..f7d73f0d --- /dev/null +++ b/src/main/kotlin/Archive.kt @@ -0,0 +1,40 @@ +class Archive(val name: String) { + private val notes = mutableListOf() + + fun showMenu() { + while (true) { + println("Список заметок в архиве '$name':") + println("0. Создать заметку") + for ((index, note) in notes.withIndex()) { + println("${index + 1}. ${note.title}") + } + println("${notes.size + 1}. Назад") + val note = NotesApp() + val choice = note.readUserInput() + when (choice) { + 0 -> createNote() + in 1..notes.size -> notes[choice - 1].show() + notes.size + 1 -> break + else -> println("Неверный ввод. Попробуйте снова.") + } + } + } + + + private fun createNote() { + println("Введите заголовок заметки:") + val title = readLine()?.trim() + if (title.isNullOrEmpty()) { + println("Заголовок не может быть пустым.") + return + } + println("Введите текст заметки:") + val content = readLine()?.trim() + if (content.isNullOrEmpty()) { + println("Текст заметки не может быть пустым.") + return + } + notes.add(Note(title, content)) + println("Заметка '$title' создана.") + } +} diff --git a/src/main/kotlin/Main.kt b/src/main/kotlin/Main.kt index aade54c5..f297b521 100644 --- a/src/main/kotlin/Main.kt +++ b/src/main/kotlin/Main.kt @@ -1,3 +1,4 @@ -fun main(args: Array) { - println("Hello World!") -} \ No newline at end of file +fun main() { + val app = NotesApp() + app.start() +} diff --git a/src/main/kotlin/MenuManager.kt b/src/main/kotlin/MenuManager.kt new file mode 100644 index 00000000..dcef7e42 --- /dev/null +++ b/src/main/kotlin/MenuManager.kt @@ -0,0 +1,27 @@ +import java.util.Scanner + +class MenuManager(private val scanner: Scanner) { + + fun showMenu(menuItems: List Unit>>) { + while (true) { + println("Выберите пункт меню:") + menuItems.forEachIndexed { index, item -> + println("$index. ${item.first}") + } + println("Введите номер пункта (или 'выход' для выхода):") + val input = scanner.nextLine() + + if (input.lowercase() == "выход") { + println("Выход из программы.") + return + } + + val index = input.toIntOrNull() + if (index != null && index in menuItems.indices) { + menuItems[index].second() + } else { + println("Неверный ввод. Пожалуйста, введите номер пункта.") + } + } + } +} diff --git a/src/main/kotlin/Note.kt b/src/main/kotlin/Note.kt new file mode 100644 index 00000000..cb248ce8 --- /dev/null +++ b/src/main/kotlin/Note.kt @@ -0,0 +1,8 @@ +class Note(val title: String, private val content: String) { + fun show() { + println("Заголовок: $title") + println("Содержание: $content") + println("Нажмите Enter, чтобы вернуться.") + readLine() + } +} diff --git a/src/main/kotlin/NotesApp.kt b/src/main/kotlin/NotesApp.kt new file mode 100644 index 00000000..8bc44b18 --- /dev/null +++ b/src/main/kotlin/NotesApp.kt @@ -0,0 +1,43 @@ +class NotesApp { + private val archives = mutableListOf() + + fun start() { + while (true) { + println("Список архивов:") + println("0. Создать архив") + for ((index, archive) in archives.withIndex()) { + println("${index + 1}. ${archive.name}") + } + println("${archives.size + 1}. Выход") + + val choice = readUserInput() + when (choice) { + 0 -> createArchive() + in 1..archives.size -> archives[choice - 1].showMenu() + archives.size + 1 -> break + else -> println("Неверный ввод. Попробуйте снова.") + } + } + } + + private fun createArchive() { + println("Введите имя архива:") + val name = readLine()?.trim() + if (name.isNullOrEmpty()) { + println("Имя архива не может быть пустым.") + return + } + archives.add(Archive(name)) + println("Архив '$name' создан.") + } + + fun readUserInput(): Int { + while (true) { + val input = readLine() + if (input != null && input.toIntOrNull() != null) { + return input.toInt() + } + println("Введите число.") + } + } +}