diff --git a/src/main/kotlin/Archive.kt b/src/main/kotlin/Archive.kt new file mode 100644 index 00000000..4068ddae --- /dev/null +++ b/src/main/kotlin/Archive.kt @@ -0,0 +1,2 @@ +data class Archive(val name: String, val notes: MutableList = mutableListOf()) +data class Note(val title: String, val content: String) diff --git a/src/main/kotlin/ArchiveManager.kt b/src/main/kotlin/ArchiveManager.kt new file mode 100644 index 00000000..21bca797 --- /dev/null +++ b/src/main/kotlin/ArchiveManager.kt @@ -0,0 +1,41 @@ + +import java.util.Scanner +class ArchiveManager { + private val archives = mutableListOf() + + fun showArchiveMenu() { + val menuScreen = MenuScreen() + val options = mutableListOf Unit>>( + "Создать архив" to ::createArchive, + "Выход" to ::exitApp + ) + + archives.forEachIndexed { index, archive -> + options.add("${index + 2}. ${archive.name}" to { showNotesMenu(archive) }) + } + + menuScreen.showMenu("Список архивов:", options) + } + + private fun createArchive() { + println("Введите название архива:") + val name = readLine().orEmpty().trim() + if (name.isNotEmpty()) { + val archive = Archive(name) + archives.add(archive) + println("Архив \"$name\" создан.") + } else { + println("Название архива не может быть пустым.") + } + showArchiveMenu() + } + + private fun showNotesMenu(archive: Archive) { + val notesManager = NotesManager(this, archive) + notesManager.showNotesMenu() + } + + private fun exitApp() { + println("Выход из приложения.") + } +} \ No newline at end of file diff --git a/src/main/kotlin/Main.kt b/src/main/kotlin/Main.kt index aade54c5..96548c71 100644 --- a/src/main/kotlin/Main.kt +++ b/src/main/kotlin/Main.kt @@ -1,3 +1,4 @@ -fun main(args: Array) { - println("Hello World!") +fun main() { + val archiveManager = ArchiveManager() + archiveManager.showArchiveMenu() } \ No newline at end of file diff --git a/src/main/kotlin/MenuScreen.kt b/src/main/kotlin/MenuScreen.kt new file mode 100644 index 00000000..c614e448 --- /dev/null +++ b/src/main/kotlin/MenuScreen.kt @@ -0,0 +1,24 @@ +class MenuScreen { + fun showMenu(title: String, options: List Unit>>) { + while (true) { + println(title) + options.forEachIndexed { index, option -> + println("$index. ${option.first}") + } + print("Выберите пункт: ") + + val input = readLine() + if (input != null && input.isNotBlank() && input.all { it.isDigit() }) { + val choice = input.toInt() + if (choice in options.indices) { + options[choice].second.invoke() + break + } else { + println("Нет такого пункта. Попробуйте еще раз.") + } + } else { + println("Вы не ввели корректное число, попробуйте снова.") + } + } +} +} \ No newline at end of file diff --git a/src/main/kotlin/NotesManager.kt b/src/main/kotlin/NotesManager.kt new file mode 100644 index 00000000..281b4ea7 --- /dev/null +++ b/src/main/kotlin/NotesManager.kt @@ -0,0 +1,47 @@ +class NotesManager( + private val archiveManager: ArchiveManager, private val archive: Archive) { + fun showNotesMenu() { + val menuScreen = MenuScreen() + val options = mutableListOf Unit>>( + "Создать заметку" to ::createNote, + "Назад" to ::goBack + ) + + archive.notes.forEachIndexed { index, note -> + options.add("${index + 2}. ${note.title}" to { showNoteContent(note) }) + } + + menuScreen.showMenu("Список заметок в архиве \"${archive.name}\":", options) + } + + private fun createNote() { + println("Введите название заметки:") + val title = readLine().orEmpty().trim() + if (title.isNotEmpty()) { + println("Введите содержание заметки:") + val content = readLine().orEmpty().trim() + if (content.isNotEmpty()) { + val note = Note(title, content) + archive.notes.add(note) + println("Заметка \"$title\" создана.") + } else { + println("Содержание заметки не может быть пустым.") + } + } else { + println("Название заметки не может быть пустым.") + } + showNotesMenu() + } + + private fun showNoteContent(note: Note) { + println("Заметка: ${note.title}") + println(note.content) + println("Для продолжения нажмите Enter.") + readLine() + showNotesMenu() + } + + private fun goBack() { + archiveManager.showArchiveMenu() + } +} \ No newline at end of file