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/.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/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/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 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