From 988f071cb3b7e5b2647ea6acdc628cb3db76e014 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=90=D0=BD=D0=B4=D1=80=D0=B5=D0=B9=20=D0=95=D1=80=D0=BC?= =?UTF-8?q?=D0=BE=D0=BB=D0=B8=D0=BD?= Date: Wed, 16 Jul 2025 18:27:51 +0300 Subject: [PATCH 1/4] feat: notes tracker --- .idea/caches/deviceStreaming.xml | 835 +++++++++++++++++++++++++++++++ src/main/kotlin/ArchiveMenu.kt | 90 ++++ src/main/kotlin/MainMenu.kt | 2 + src/main/kotlin/Menu.kt | 27 + src/main/kotlin/NoteMenu.kt | 2 + 5 files changed, 956 insertions(+) create mode 100644 .idea/caches/deviceStreaming.xml create mode 100644 src/main/kotlin/ArchiveMenu.kt create mode 100644 src/main/kotlin/MainMenu.kt create mode 100644 src/main/kotlin/Menu.kt create mode 100644 src/main/kotlin/NoteMenu.kt diff --git a/.idea/caches/deviceStreaming.xml b/.idea/caches/deviceStreaming.xml new file mode 100644 index 00000000..9aaec77f --- /dev/null +++ b/.idea/caches/deviceStreaming.xml @@ -0,0 +1,835 @@ + + + + + + \ 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 00000000..a125af7e --- /dev/null +++ b/src/main/kotlin/ArchiveMenu.kt @@ -0,0 +1,90 @@ +import java.util.Scanner + +class SelectMenu() { + private val scanner: Scanner = Scanner(System.`in`) + + + fun addArchive(archives: HashMap>) { + print("Введите название архива: ") + val archiveName = scanner.nextLine() + if (!archives.containsKey(archiveName)) { + archives[archiveName] = mutableListOf() + println("Архив '$archiveName' создан.") + } else { + println("Архив с таким именем уже существует.") + } + } + + + fun selectArchive(archives: HashMap>) { + println("Список архивов:") + archives.keys.forEachIndexed { index, key -> println("${index + 1}. $key") } + println("0. Вернуться назад") + print("Ваш выбор: ") + val choice = scanner.nextLine() + + if (choice == "0") { + return + } else { + try { + val selectedArchiveIndex = choice.toInt() - 1 + if (selectedArchiveIndex in 0 until archives.size) { + val selectedArchive = archives.keys.toList()[selectedArchiveIndex] + println("Вы выбрали архив $selectedArchive.") + selectArchiveActions(archives[selectedArchive]!!) + } else { + println("Некорректный выбор. Попробуйте снова.") + } + } catch (e: NumberFormatException) { + println("Пожалуйста, введите целое число.") + } + } + } + + + fun selectArchiveActions(notes: MutableList) { + println("Выберите действие:") + println("1. Просмотр заметки") + println("2. Создать заметку") + println("3. Выйти на верхний уровень меню") + + print("Ваш выбор: ") + val choice = scanner.nextLine() + + when (choice) { + "1" -> selectNote(notes) + "2" -> createNote(notes) + "3" -> return + else -> println("Некорректный выбор. Попробуйте снова.") + } + } + + fun selectNote(notes: MutableList) { + println("Список заметок в архиве:") + notes.forEachIndexed { index, note -> println("\"${index + 1}. $note\"") } + println("0. Вернуться назад") + print("Ваш выбор: ") + val choice = scanner.nextLine() + + if (choice == "0") { + return + } else { + println("Вы выбрали заметку ${notes[choice.toInt()]}.") + showNote(notes[choice.toInt()]) + } + } + + fun createNote(notes: MutableList) { + print("Введите текст заметки: ") + val noteText = scanner.nextLine() + notes.add(noteText) + println("Заметка '$noteText' создана.") + } + + fun showNote(noteText: String) { + println("Текст заметки:") + println(noteText) + println("Нажмите Enter, чтобы вернуться назад.") + scanner.nextLine() + } +} \ No newline at end of file diff --git a/src/main/kotlin/MainMenu.kt b/src/main/kotlin/MainMenu.kt new file mode 100644 index 00000000..55f9dd47 --- /dev/null +++ b/src/main/kotlin/MainMenu.kt @@ -0,0 +1,2 @@ +class MainMenu { +} \ 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..c2d3ea6a --- /dev/null +++ b/src/main/kotlin/Menu.kt @@ -0,0 +1,27 @@ +import java.util.Scanner + +abstract class MainMenu(private val scanner: Scanner) { + protected val items = mutableListOf() + + fun show() { + while (true) { + items.forEach { item -> println("${item.index}. ${item.title}") } + print("Ваш выбор: ") + val choice = scanner.nextLine() + + try { + val selectedIndex = choice.toInt() - 1 + if (selectedIndex in 0 until items.size) { + items[selectedIndex].action() + break + } else { + println("Некорректный выбор. Попробуйте снова.") + } + } catch (e: NumberFormatException) { + println("Пожалуйста, введите целое число.") + } + } + } + + data class Item(val index: Int, val title: String, val action: () -> Unit) +} \ 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 00000000..410c7412 --- /dev/null +++ b/src/main/kotlin/NoteMenu.kt @@ -0,0 +1,2 @@ +class NoteMenu { +} \ No newline at end of file From ddbcd19f78fa75cb98481fb315294ebbf8987854 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=90=D0=BD=D0=B4=D1=80=D0=B5=D0=B9=20=D0=95=D1=80=D0=BC?= =?UTF-8?q?=D0=BE=D0=BB=D0=B8=D0=BD?= Date: Thu, 17 Jul 2025 12:24:05 +0300 Subject: [PATCH 2/4] feat:notes --- .idea/caches/deviceStreaming.xml | 0 src/main/kotlin/ArchiveMenu.kt | 59 ++++++++++++++++++++++++++++++++ src/main/kotlin/MainMenu.kt | 26 ++++++++++++++ src/main/kotlin/Menu.kt | 34 ++++++++++++++++++ src/main/kotlin/NoteMenu.kt | 48 ++++++++++++++++++++++++++ 5 files changed, 167 insertions(+) create mode 100644 .idea/caches/deviceStreaming.xml create mode 100644 src/main/kotlin/ArchiveMenu.kt create mode 100644 src/main/kotlin/MainMenu.kt create mode 100644 src/main/kotlin/Menu.kt create mode 100644 src/main/kotlin/NoteMenu.kt diff --git a/.idea/caches/deviceStreaming.xml b/.idea/caches/deviceStreaming.xml new file mode 100644 index 00000000..e69de29b diff --git a/src/main/kotlin/ArchiveMenu.kt b/src/main/kotlin/ArchiveMenu.kt new file mode 100644 index 00000000..6b3fa6ce --- /dev/null +++ b/src/main/kotlin/ArchiveMenu.kt @@ -0,0 +1,59 @@ +import java.util.Scanner + +class ArchiveMenu(scanner: Scanner) : Menu(scanner) { + init { + items.add(Item(0, "Вернуться назад", ::goBack)) // Добавляем пункт "Вернуться назад" + items.add(Item(1, "Создать архив", ::createArchive)) + items.add(Item(2, "Просмотр архива", ::viewArchives)) + } + + private fun createArchive(archives: HashMap>) { + print("Введите название архива: ") + val archiveName = scanner.nextLine() + if (archiveName.isNotEmpty()) { + if (!archives.containsKey(archiveName)) { + archives[archiveName] = HashMap() + println("Архив '$archiveName' создан.") + } else { + println("Архив с таким именем уже существует.") + } + } else { + println("Имя архива не может быть пустым.") + } + goBack(archives) // Добавляем возврат в главное меню после создания архива + } + + private fun viewArchives(archives: HashMap>) { + println("Список архивов:") + archives.keys.forEachIndexed { index, key -> println("${index + 1}. $key") } + println("0. Вернуться назад") + print("Ваш выбор: ") + val choice = scanner.nextLine() + + try { + val selectedIndex = choice.toInt() - 1 // Корректируем индекс, так как выбор начинается с 1 + if (selectedIndex in 0 until archives.size) { + val selectedArchive = archives.keys.toList()[selectedIndex] + println("Вы выбрали архив $selectedArchive.") + viewNotesInArchive(selectedArchive, archives) // Вызываем метод для просмотра заметок + } else if (choice == "0") { + goBack(archives) + } else { + println("Некорректный выбор. Попробуйте снова.") + } + } catch (e: NumberFormatException) { + println("Пожалуйста, введите целое число.") + } + } + + private fun viewNotesInArchive(archiveName: String, archives: HashMap>) { + if (archives.containsKey(archiveName)) { + val notes = archives[archiveName]!! + println("Список заметок в архиве $archiveName:") + notes.forEach { (title, content) -> println("Заголовок: $title, Содержание: $content") } + goBack(archives) // Добавляем возврат в главное меню после просмотра заметок + } else { + println("Архив с таким именем не найден.") + } + } +} diff --git a/src/main/kotlin/MainMenu.kt b/src/main/kotlin/MainMenu.kt new file mode 100644 index 00000000..dd6cc765 --- /dev/null +++ b/src/main/kotlin/MainMenu.kt @@ -0,0 +1,26 @@ +import java.util.Scanner +import kotlin.system.exitProcess + +class MainMenu(scanner: Scanner) : Menu(scanner) { + init { + items.add(Item(0, "Выход", ::goExit)) + items.add(Item(1, "Архив", ::archiveMenu)) + items.add(Item(2, "Заметка", ::noteMenu)) + } + + + private fun goExit(archives: HashMap>) { + System.exit(1) + } + + + private fun archiveMenu(archives: HashMap>) { + val archiveMenu = ArchiveMenu(scanner) + archiveMenu.show(archives) + } + + private fun noteMenu(archives: HashMap>) { + val noteMenu = NoteMenu(scanner, archives) + noteMenu.show(archives) + } +} \ 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..816891e4 --- /dev/null +++ b/src/main/kotlin/Menu.kt @@ -0,0 +1,34 @@ +import java.util.Scanner + +abstract class Menu(protected val scanner: Scanner) { + protected val items = mutableListOf() + + fun show(archives: HashMap>) { + while (true) { + items.forEach { item -> println("${item.index}. ${item.title}") } + print("Ваш выбор: ") + val choice = scanner.nextLine() + + try { + val selectedIndex = choice.toInt() + if (selectedIndex in 0 until items.size) { + items[selectedIndex].action(archives) + break + } else { + println("Некорректный выбор. Попробуйте снова.") + } + } catch (e: NumberFormatException) { + println("Пожалуйста, введите целое число.") + } + } + } + + protected fun goBack(archives: HashMap>) { + val mainMenu = MainMenu(scanner) + mainMenu.show(archives) + } + + + + data class Item(val index: Int, val title: String, val action: (HashMap>) -> Unit) +} \ 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 00000000..961f76b3 --- /dev/null +++ b/src/main/kotlin/NoteMenu.kt @@ -0,0 +1,48 @@ +import java.util.Scanner + +class NoteMenu(scanner: Scanner, private val archives: HashMap>) : Menu(scanner) { + init { + items.add(Item(0, "Вернуться назад", ::goBack)) // Добавляем пункт "Вернуться назад" + items.add(Item(1, "Создать заметку", ::createNote)) + items.add(Item(2, "Просмотр заметки", ::viewNotes)) + } + + private fun createNote(archives: HashMap>) { + print("Введите название архива: ") + val archiveName = scanner.nextLine() + if (archives.containsKey(archiveName)) { + print("Введите заголовок заметки: ") + val noteTitle = scanner.nextLine() + print("Введите текст заметки: ") + val noteContent = scanner.nextLine() + if (noteTitle.isNotEmpty() && noteContent.isNotEmpty()) { + archives[archiveName]!![noteTitle] = noteContent + println("Заметка '$noteTitle' создана.") + } else { + println("Заголовок или текст заметки не могут быть пустыми.") + } + } else { + println("Архив с таким именем не найден.") + } + } + + private fun viewNotes(archives: HashMap>) { + print("Введите название архива: ") + val archiveName = scanner.nextLine() + if (archives.containsKey(archiveName)) { + viewNotesInArchive(archiveName, archives) + } else { + println("Архив с таким именем не найден.") + } + } + + private fun viewNotesInArchive(archiveName: String, archives: HashMap>) { + if (archives.containsKey(archiveName)) { + val notes = archives[archiveName]!! + println("Список заметок в архиве $archiveName:") + notes.forEach { (title, content) -> println("Заголовок: $title, Содержание: $content") } + } else { + println("Архив с таким именем не найден.") + } + } +} From c552e9d9f215af736e02f8c47396179c28a944ae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=90=D0=BD=D0=B4=D1=80=D0=B5=D0=B9=20=D0=95=D1=80=D0=BC?= =?UTF-8?q?=D0=BE=D0=BB=D0=B8=D0=BD?= Date: Fri, 18 Jul 2025 19:03:03 +0300 Subject: [PATCH 3/4] fix: correct notes --- src/main/kotlin/ArchiveMenu.kt | 28 ++++++++++++++++++++++++++++ src/main/kotlin/MainMenu.kt | 1 + src/main/kotlin/NoteMenu.kt | 22 +++++++++++++++++----- 3 files changed, 46 insertions(+), 5 deletions(-) diff --git a/src/main/kotlin/ArchiveMenu.kt b/src/main/kotlin/ArchiveMenu.kt index 6b3fa6ce..96d1e7b7 100644 --- a/src/main/kotlin/ArchiveMenu.kt +++ b/src/main/kotlin/ArchiveMenu.kt @@ -5,6 +5,8 @@ class ArchiveMenu(scanner: Scanner) : Menu(scanner) { items.add(Item(0, "Вернуться назад", ::goBack)) // Добавляем пункт "Вернуться назад" items.add(Item(1, "Создать архив", ::createArchive)) items.add(Item(2, "Просмотр архива", ::viewArchives)) + items.add(Item(3, "Создать заметку", ::createNote)) + } private fun createArchive(archives: HashMap>) { @@ -16,9 +18,11 @@ class ArchiveMenu(scanner: Scanner) : Menu(scanner) { println("Архив '$archiveName' создан.") } else { println("Архив с таким именем уже существует.") + goBack(archives) } } else { println("Имя архива не может быть пустым.") + goBack(archives) } goBack(archives) // Добавляем возврат в главное меню после создания архива } @@ -43,6 +47,7 @@ class ArchiveMenu(scanner: Scanner) : Menu(scanner) { } } catch (e: NumberFormatException) { println("Пожалуйста, введите целое число.") + goBack(archives) } } @@ -56,4 +61,27 @@ class ArchiveMenu(scanner: Scanner) : Menu(scanner) { println("Архив с таким именем не найден.") } } + + private fun createNote(archives: HashMap>) { + print("Введите название архива: ") + val archiveName = scanner.nextLine().trim() + if (archiveName.isNotEmpty() && archives.containsKey(archiveName)) { + print("Введите заголовок заметки: ") + val noteTitle = scanner.nextLine().trim() + print("Введите текст заметки: ") + val noteContent = scanner.nextLine().trim() + + if (noteTitle.isNotEmpty() && noteContent.isNotEmpty()) { + archives[archiveName]!![noteTitle] = noteContent + println("Заметка '$noteTitle' создана.") + } else { + println("Заголовок или текст заметки не могут быть пустыми.") + } + } else { + println("Архив с таким именем не найден или название архива пустое.") + } + goBack(archives) // Добавляем возврат в главное меню после создания заметки + } + + } diff --git a/src/main/kotlin/MainMenu.kt b/src/main/kotlin/MainMenu.kt index dd6cc765..390998ef 100644 --- a/src/main/kotlin/MainMenu.kt +++ b/src/main/kotlin/MainMenu.kt @@ -10,6 +10,7 @@ class MainMenu(scanner: Scanner) : Menu(scanner) { private fun goExit(archives: HashMap>) { + println("До свидания!") System.exit(1) } diff --git a/src/main/kotlin/NoteMenu.kt b/src/main/kotlin/NoteMenu.kt index 961f76b3..2d3da348 100644 --- a/src/main/kotlin/NoteMenu.kt +++ b/src/main/kotlin/NoteMenu.kt @@ -9,20 +9,24 @@ class NoteMenu(scanner: Scanner, private val archives: HashMap>) { print("Введите название архива: ") - val archiveName = scanner.nextLine() - if (archives.containsKey(archiveName)) { + val archiveName = scanner.nextLine().trim() + if (archiveName.isNotEmpty() && archives.containsKey(archiveName)) { print("Введите заголовок заметки: ") - val noteTitle = scanner.nextLine() + val noteTitle = scanner.nextLine().trim() print("Введите текст заметки: ") - val noteContent = scanner.nextLine() + val noteContent = scanner.nextLine().trim() + if (noteTitle.isNotEmpty() && noteContent.isNotEmpty()) { archives[archiveName]!![noteTitle] = noteContent println("Заметка '$noteTitle' создана.") } else { println("Заголовок или текст заметки не могут быть пустыми.") + goBack(archives) } } else { - println("Архив с таким именем не найден.") + println("Архив с таким именем не найден или название архива пустое.") + goBack(archives) + } } @@ -31,8 +35,12 @@ class NoteMenu(scanner: Scanner, private val archives: HashMap println("Заголовок: $title, Содержание: $content") } + goBack(archives) + } else { println("Архив с таким именем не найден.") + goBack(archives) + } } } From 908b95ea34ce6782b73d8c039803bc324c0d483d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=90=D0=BD=D0=B4=D1=80=D0=B5=D0=B9=20=D0=95=D1=80=D0=BC?= =?UTF-8?q?=D0=BE=D0=BB=D0=B8=D0=BD?= Date: Sat, 19 Jul 2025 12:22:11 +0300 Subject: [PATCH 4/4] fix: bugs with exit and empty name archiv --- src/main/kotlin/ArchiveMenu.kt | 2 +- src/main/kotlin/NoteMenu.kt | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main/kotlin/ArchiveMenu.kt b/src/main/kotlin/ArchiveMenu.kt index 96d1e7b7..1ce399b9 100644 --- a/src/main/kotlin/ArchiveMenu.kt +++ b/src/main/kotlin/ArchiveMenu.kt @@ -11,7 +11,7 @@ class ArchiveMenu(scanner: Scanner) : Menu(scanner) { private fun createArchive(archives: HashMap>) { print("Введите название архива: ") - val archiveName = scanner.nextLine() + val archiveName = scanner.nextLine().trim() if (archiveName.isNotEmpty()) { if (!archives.containsKey(archiveName)) { archives[archiveName] = HashMap() diff --git a/src/main/kotlin/NoteMenu.kt b/src/main/kotlin/NoteMenu.kt index 2d3da348..262f6a05 100644 --- a/src/main/kotlin/NoteMenu.kt +++ b/src/main/kotlin/NoteMenu.kt @@ -19,6 +19,7 @@ class NoteMenu(scanner: Scanner, private val archives: HashMap