From 22287a7dde6ce95d1f51892a08b34504ef12f4a6 Mon Sep 17 00:00:00 2001 From: AnDi24 Date: Tue, 4 Mar 2025 22:24:55 +1000 Subject: [PATCH] =?UTF-8?q?=D0=9F=D1=80=D0=BE=D0=B5=D0=BA=D1=82=203(=D0=9A?= =?UTF-8?q?=D0=BE=D1=82=D0=BB=D0=B8=D0=BD)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .idea/caches/deviceStreaming.xml | 558 +++++++++++++++++++++++++++++++ .idea/misc.xml | 2 +- src/main/kotlin/Archive.kt | 13 + src/main/kotlin/Main.kt | 68 +++- src/main/kotlin/MenuNavi.kt | 29 ++ src/main/kotlin/Note.kt | 6 + 6 files changed, 674 insertions(+), 2 deletions(-) create mode 100644 .idea/caches/deviceStreaming.xml create mode 100644 src/main/kotlin/Archive.kt create mode 100644 src/main/kotlin/MenuNavi.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 00000000..9b915e85 --- /dev/null +++ b/.idea/caches/deviceStreaming.xml @@ -0,0 +1,558 @@ + + + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml index 9c8e7400..f03c9487 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..46a1ee36 --- /dev/null +++ b/src/main/kotlin/Archive.kt @@ -0,0 +1,13 @@ + +class Archive (val name: String) { + val notes = mutableListOf() +} + + + + + + + + + diff --git a/src/main/kotlin/Main.kt b/src/main/kotlin/Main.kt index aade54c5..73e59211 100644 --- a/src/main/kotlin/Main.kt +++ b/src/main/kotlin/Main.kt @@ -1,3 +1,69 @@ +import java.util.Scanner +import kotlin.system.exitProcess + +val archives = mutableListOf() + +fun showMenu(){ + val menu = MenuNavi("Список архивов") + menu.menuItems.add("Создать архив" to {createArchive()}) + archives.forEachIndexed {index, archive -> + menu.menuItems.add(archive.name to {showArchMenu(index)}) + } + menu.funMenu{ exitProcess(0) } +} + +fun createArchive() { + println("Введите имя архива") + var name = Scanner(System.`in`).nextLine() + while (name.trim().isEmpty()) { + println("Имя архива должно содержать хотя бы 1 символ") + name = Scanner(System.`in`).nextLine() + } + archives.add(Archive(name)) + showMenu() +} + +fun showArchMenu(archIndex: Int) { + val archive = archives[archIndex] + val menu = MenuNavi("Список заметок") + menu.menuItems.add("Создать заметку" to {createNote(archive)}) + archive.notes.forEachIndexed { index, note -> + menu.menuItems.add(note.name to { showNoteMenu(archive, index) }) + } + menu.funMenu{showMenu()} +} + +fun createNote(archive: Archive) { + println("Введите имя заметки") + var name = Scanner(System.`in`).nextLine() + while (name.trim().isEmpty()) { + println("Имя заметки должно содержать хотя бы 1 символ") + name = Scanner(System.`in`).nextLine() + } + +println("Введите текст заметки:") + var text = Scanner(System.`in`).nextLine() + while (text.trim().isEmpty()) { + println("В заметке пусто, повторите ввод") + text = Scanner(System.`in`).nextLine() +} + +archive.notes.add(Note(name, text)) +println("Заметка '$name' создана.") +showArchMenu(archives.indexOf(archive)) +} + +fun showNoteMenu(archive: Archive, noteIndex: Int) { + val note = archive.notes[noteIndex] + println("Заметка: ${note.name}") + println("Текст: ${note.text}") + println("Для возврата нажмите Enter или введите любой символ") + readlnOrNull() + showArchMenu(archives.indexOf(archive)) +} + fun main(args: Array) { - println("Hello World!") + println("Приложение Заметки") + showMenu() + } \ No newline at end of file diff --git a/src/main/kotlin/MenuNavi.kt b/src/main/kotlin/MenuNavi.kt new file mode 100644 index 00000000..b3d3a549 --- /dev/null +++ b/src/main/kotlin/MenuNavi.kt @@ -0,0 +1,29 @@ +import java.util.Scanner + +class MenuNavi(val name: String) { + + val menuItems = mutableListOf Unit>>() + + fun funMenu(exit:() -> Unit = {}){ + while (true) { + println("$name:") + + menuItems.forEachIndexed { index, pair -> + println("$index. ${pair.first}") + } + if (menuItems.size !== 0) println("${menuItems.size}. Выход") else println("1. Выход") + + val i = Scanner(System.`in`).nextLine().toIntOrNull() + if (i != null) { + if (i < menuItems.size) { + menuItems[i].second() + return} + } + if (i == menuItems.size) { + exit() + } else { + println("Неверный ввод, попробуйте снова") + } + } + } +} \ 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..4c90aed1 --- /dev/null +++ b/src/main/kotlin/Note.kt @@ -0,0 +1,6 @@ + +class Note (val name: String, text: String?) { + var text: String = text.toString() +} + +