From d88ffeea881b12058a41eaa00499cef1ab203955 Mon Sep 17 00:00:00 2001 From: user Date: Fri, 12 Sep 2025 13:48:40 +0300 Subject: [PATCH 1/3] complete --- .idea/caches/deviceStreaming.xml | 848 +++++++++++++++++++++++++++++++ .idea/misc.xml | 1 - src/main/kotlin/Main.kt | 95 +++- 3 files changed, 940 insertions(+), 4 deletions(-) create mode 100644 .idea/caches/deviceStreaming.xml diff --git a/.idea/caches/deviceStreaming.xml b/.idea/caches/deviceStreaming.xml new file mode 100644 index 00000000..528f19ec --- /dev/null +++ b/.idea/caches/deviceStreaming.xml @@ -0,0 +1,848 @@ + + + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml index 9c8e7400..f515117b 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -1,4 +1,3 @@ - diff --git a/src/main/kotlin/Main.kt b/src/main/kotlin/Main.kt index aade54c5..7b5bc683 100644 --- a/src/main/kotlin/Main.kt +++ b/src/main/kotlin/Main.kt @@ -1,3 +1,92 @@ -fun main(args: Array) { - println("Hello World!") -} \ No newline at end of file +import java.util.Scanner + +data class Note(val text: String) +data class Archive(val name: String, val notes: MutableList = mutableListOf()) + +fun main() { + val scanner = Scanner(System.`in`) + val archives = mutableListOf() + + fun inputNumber(limit: Int): Int { + while (true) { + val input = scanner.nextLine() + val num = input.toIntOrNull() + if (num == null) { + println("Ошибка: введите цифру.") + } else if (num !in 0 until limit) { + println("Ошибка: такого пункта нет.") + } else { + return num + } + print("Повторите ввод: ") + } + } + + fun viewNoteMenu(note: Note) { + while (true) { + println("\n--- Просмотр заметки ---") + println(note.text) + println("0. Назад") + + when (inputNumber(1)) { + 0 -> return + } + } + } + + fun createNoteMenu(archive: Archive) { + println("\nВведите текст новой заметки:") + val text = scanner.nextLine() + archive.notes.add(Note(text)) + println("Заметка добавлена!") + } + + fun notesMenu(archive: Archive) { + while (true) { + println("\n--- Архив: ${archive.name} ---") + println("0. Создать заметку") + archive.notes.forEachIndexed { i, note -> + println("${i + 1}. ${note.text.take(20)}...") + } + println("${archive.notes.size + 1}. Назад") + + val choice = inputNumber(archive.notes.size + 2) + when (choice) { + 0 -> createNoteMenu(archive) + in 1..archive.notes.size -> viewNoteMenu(archive.notes[choice - 1]) + archive.notes.size + 1 -> return + } + } + } + + fun createArchiveMenu() { + println("\nВведите название архива:") + val name = scanner.nextLine() + archives.add(Archive(name)) + println("Архив добавлен!") + } + + fun archivesMenu() { + while (true) { + println("\n--- Список архивов ---") + println("0. Создать архив") + archives.forEachIndexed { i, archive -> + println("${i + 1}. ${archive.name}") + } + println("${archives.size + 1}. Выход из программы") + + val choice = inputNumber(archives.size + 2) + when (choice) { + 0 -> createArchiveMenu() + in 1..archives.size -> notesMenu(archives[choice - 1]) + archives.size + 1 -> { + println("Выход из программы...") + return + } + } + } + } + + println("=== Программа Заметки ===") + archivesMenu() +} From 9ec049af49005eba7ce78bd09d5aa783452e9dd9 Mon Sep 17 00:00:00 2001 From: user Date: Fri, 12 Sep 2025 16:58:07 +0300 Subject: [PATCH 2/3] complete2 --- src/main/kotlin/Main.kt | 45 +++++++++++++++++++++++++++++++---------- 1 file changed, 34 insertions(+), 11 deletions(-) diff --git a/src/main/kotlin/Main.kt b/src/main/kotlin/Main.kt index 7b5bc683..a9f91537 100644 --- a/src/main/kotlin/Main.kt +++ b/src/main/kotlin/Main.kt @@ -1,6 +1,6 @@ import java.util.Scanner -data class Note(val text: String) +data class Note(val name: String, val text: String) data class Archive(val name: String, val notes: MutableList = mutableListOf()) fun main() { @@ -25,7 +25,8 @@ fun main() { fun viewNoteMenu(note: Note) { while (true) { println("\n--- Просмотр заметки ---") - println(note.text) + println("Название: ${note.name}") + println("Текст: ${note.text}") println("0. Назад") when (inputNumber(1)) { @@ -35,10 +36,25 @@ fun main() { } fun createNoteMenu(archive: Archive) { - println("\nВведите текст новой заметки:") - val text = scanner.nextLine() - archive.notes.add(Note(text)) - println("Заметка добавлена!") + while (true) { + println("\nВведите название новой заметки:") + val name = scanner.nextLine().trim() + if (name.isEmpty()) { + println("Ошибка: название заметки не может быть пустым!") + continue + } + + println("Введите текст заметки:") + val text = scanner.nextLine().trim() + if (text.isEmpty()) { + println("Ошибка: текст заметки не может быть пустым!") + continue + } + + archive.notes.add(Note(name, text)) + println("Заметка добавлена!") + return + } } fun notesMenu(archive: Archive) { @@ -46,7 +62,7 @@ fun main() { println("\n--- Архив: ${archive.name} ---") println("0. Создать заметку") archive.notes.forEachIndexed { i, note -> - println("${i + 1}. ${note.text.take(20)}...") + println("${i + 1}. ${note.name}") } println("${archive.notes.size + 1}. Назад") @@ -60,10 +76,17 @@ fun main() { } fun createArchiveMenu() { - println("\nВведите название архива:") - val name = scanner.nextLine() - archives.add(Archive(name)) - println("Архив добавлен!") + while (true) { + println("\nВведите название архива:") + val name = scanner.nextLine().trim() + if (name.isEmpty()) { + println("Ошибка: имя архива не может быть пустым!") + } else { + archives.add(Archive(name)) + println("Архив добавлен!") + return + } + } } fun archivesMenu() { From 29afcf0e5c1b07ea376aa5deeb0e1b0480453d93 Mon Sep 17 00:00:00 2001 From: user Date: Fri, 12 Sep 2025 17:13:44 +0300 Subject: [PATCH 3/3] complete --- src/main/kotlin/Main.kt | 113 +-------------------- src/main/kotlin/menus/ArchivesMenu.kt | 36 +++++++ src/main/kotlin/menus/CreateArchiveMenu.kt | 11 ++ src/main/kotlin/menus/CreateNoteMenu.kt | 16 +++ src/main/kotlin/menus/NotesMenu.kt | 31 ++++++ src/main/kotlin/menus/ViewNoteMenu.kt | 16 +++ src/main/kotlin/models/Archive.kt | 6 ++ src/main/kotlin/models/Note.kt | 6 ++ 8 files changed, 125 insertions(+), 110 deletions(-) create mode 100644 src/main/kotlin/menus/ArchivesMenu.kt create mode 100644 src/main/kotlin/menus/CreateArchiveMenu.kt create mode 100644 src/main/kotlin/menus/CreateNoteMenu.kt create mode 100644 src/main/kotlin/menus/NotesMenu.kt create mode 100644 src/main/kotlin/menus/ViewNoteMenu.kt create mode 100644 src/main/kotlin/models/Archive.kt create mode 100644 src/main/kotlin/models/Note.kt diff --git a/src/main/kotlin/Main.kt b/src/main/kotlin/Main.kt index a9f91537..6c9a6199 100644 --- a/src/main/kotlin/Main.kt +++ b/src/main/kotlin/Main.kt @@ -1,115 +1,8 @@ -import java.util.Scanner - -data class Note(val name: String, val text: String) -data class Archive(val name: String, val notes: MutableList = mutableListOf()) +import menus.archivesMenu +import java.util.* fun main() { val scanner = Scanner(System.`in`) - val archives = mutableListOf() - - fun inputNumber(limit: Int): Int { - while (true) { - val input = scanner.nextLine() - val num = input.toIntOrNull() - if (num == null) { - println("Ошибка: введите цифру.") - } else if (num !in 0 until limit) { - println("Ошибка: такого пункта нет.") - } else { - return num - } - print("Повторите ввод: ") - } - } - - fun viewNoteMenu(note: Note) { - while (true) { - println("\n--- Просмотр заметки ---") - println("Название: ${note.name}") - println("Текст: ${note.text}") - println("0. Назад") - - when (inputNumber(1)) { - 0 -> return - } - } - } - - fun createNoteMenu(archive: Archive) { - while (true) { - println("\nВведите название новой заметки:") - val name = scanner.nextLine().trim() - if (name.isEmpty()) { - println("Ошибка: название заметки не может быть пустым!") - continue - } - - println("Введите текст заметки:") - val text = scanner.nextLine().trim() - if (text.isEmpty()) { - println("Ошибка: текст заметки не может быть пустым!") - continue - } - - archive.notes.add(Note(name, text)) - println("Заметка добавлена!") - return - } - } - - fun notesMenu(archive: Archive) { - while (true) { - println("\n--- Архив: ${archive.name} ---") - println("0. Создать заметку") - archive.notes.forEachIndexed { i, note -> - println("${i + 1}. ${note.name}") - } - println("${archive.notes.size + 1}. Назад") - - val choice = inputNumber(archive.notes.size + 2) - when (choice) { - 0 -> createNoteMenu(archive) - in 1..archive.notes.size -> viewNoteMenu(archive.notes[choice - 1]) - archive.notes.size + 1 -> return - } - } - } - - fun createArchiveMenu() { - while (true) { - println("\nВведите название архива:") - val name = scanner.nextLine().trim() - if (name.isEmpty()) { - println("Ошибка: имя архива не может быть пустым!") - } else { - archives.add(Archive(name)) - println("Архив добавлен!") - return - } - } - } - - fun archivesMenu() { - while (true) { - println("\n--- Список архивов ---") - println("0. Создать архив") - archives.forEachIndexed { i, archive -> - println("${i + 1}. ${archive.name}") - } - println("${archives.size + 1}. Выход из программы") - - val choice = inputNumber(archives.size + 2) - when (choice) { - 0 -> createArchiveMenu() - in 1..archives.size -> notesMenu(archives[choice - 1]) - archives.size + 1 -> { - println("Выход из программы...") - return - } - } - } - } - println("=== Программа Заметки ===") - archivesMenu() + archivesMenu(scanner) } diff --git a/src/main/kotlin/menus/ArchivesMenu.kt b/src/main/kotlin/menus/ArchivesMenu.kt new file mode 100644 index 00000000..51c31508 --- /dev/null +++ b/src/main/kotlin/menus/ArchivesMenu.kt @@ -0,0 +1,36 @@ +package menus + +import models.Archive +import java.util.* + +fun archivesMenu(scanner: Scanner) { + val archives = mutableListOf() + + fun inputNumber(limit: Int): Int { + while (true) { + val input = scanner.nextLine() + val num = input.toIntOrNull() + if (num == null || num !in 0 until limit) { + print("Ошибка: повторите ввод: ") + } else return num + } + } + + while (true) { + println("\n--- Список архивов ---") + println("0. Создать архив") + archives.forEachIndexed { i, archive -> + println("${i + 1}. ${archive.name.ifEmpty { "(без имени)" }}") + } + println("${archives.size + 1}. Выход из программы") + + when (val choice = inputNumber(archives.size + 2)) { + 0 -> createArchiveMenu(archives, scanner) + in 1..archives.size -> notesMenu(archives[choice - 1], scanner) + archives.size + 1 -> { + println("Выход из программы...") + return + } + } + } +} diff --git a/src/main/kotlin/menus/CreateArchiveMenu.kt b/src/main/kotlin/menus/CreateArchiveMenu.kt new file mode 100644 index 00000000..52bbd4cf --- /dev/null +++ b/src/main/kotlin/menus/CreateArchiveMenu.kt @@ -0,0 +1,11 @@ +package menus + +import models.Archive +import java.util.* + +fun createArchiveMenu(archives: MutableList, scanner: Scanner) { + println("\nВведите название архива (можно оставить пустым):") + val name = scanner.nextLine().trim() + archives.add(Archive(name)) + println("Архив добавлен!") +} diff --git a/src/main/kotlin/menus/CreateNoteMenu.kt b/src/main/kotlin/menus/CreateNoteMenu.kt new file mode 100644 index 00000000..46e4589c --- /dev/null +++ b/src/main/kotlin/menus/CreateNoteMenu.kt @@ -0,0 +1,16 @@ +package menus + +import models.Archive +import models.Note +import java.util.* + +fun createNoteMenu(archive: Archive, scanner: Scanner) { + println("\nВведите название новой заметки (можно оставить пустым):") + val name = scanner.nextLine().trim() + + println("Введите текст заметки (можно оставить пустым):") + val text = scanner.nextLine().trim() + + archive.notes.add(Note(name, text)) + println("Заметка добавлена!") +} diff --git a/src/main/kotlin/menus/NotesMenu.kt b/src/main/kotlin/menus/NotesMenu.kt new file mode 100644 index 00000000..f6ae6304 --- /dev/null +++ b/src/main/kotlin/menus/NotesMenu.kt @@ -0,0 +1,31 @@ +package menus + +import models.Archive +import java.util.* + +fun notesMenu(archive: Archive, scanner: Scanner) { + fun inputNumber(limit: Int): Int { + while (true) { + val input = scanner.nextLine() + val num = input.toIntOrNull() + if (num == null || num !in 0 until limit) { + print("Ошибка: повторите ввод: ") + } else return num + } + } + + while (true) { + println("\n--- Архив: ${archive.name.ifEmpty { "(без имени)" }} ---") + println("0. Создать заметку") + archive.notes.forEachIndexed { i, note -> + println("${i + 1}. ${note.name.ifEmpty { "(без названия)" }}") + } + println("${archive.notes.size + 1}. Назад") + + when (val choice = inputNumber(archive.notes.size + 2)) { + 0 -> createNoteMenu(archive, scanner) + in 1..archive.notes.size -> viewNoteMenu(archive.notes[choice - 1], scanner) + archive.notes.size + 1 -> return + } + } +} diff --git a/src/main/kotlin/menus/ViewNoteMenu.kt b/src/main/kotlin/menus/ViewNoteMenu.kt new file mode 100644 index 00000000..1212fd64 --- /dev/null +++ b/src/main/kotlin/menus/ViewNoteMenu.kt @@ -0,0 +1,16 @@ +package menus + +import models.Note +import java.util.* + +fun viewNoteMenu(note: Note, scanner: Scanner) { + while (true) { + println("\n--- Просмотр заметки ---") + println("Название: ${note.name.ifEmpty { "(без названия)" }}") + println("Текст: ${note.text.ifEmpty { "(пусто)" }}") + println("0. Назад") + + val input = scanner.nextLine() + if (input == "0") return + } +} diff --git a/src/main/kotlin/models/Archive.kt b/src/main/kotlin/models/Archive.kt new file mode 100644 index 00000000..19f103de --- /dev/null +++ b/src/main/kotlin/models/Archive.kt @@ -0,0 +1,6 @@ +package models + +data class Archive( + val name: String, + val notes: MutableList = mutableListOf() +) diff --git a/src/main/kotlin/models/Note.kt b/src/main/kotlin/models/Note.kt new file mode 100644 index 00000000..b82db9ae --- /dev/null +++ b/src/main/kotlin/models/Note.kt @@ -0,0 +1,6 @@ +package models + +data class Note( + val name: String, + val text: String +)