From cf0e004c6298d63376ad6d10ba42ba4c554b1d86 Mon Sep 17 00:00:00 2001 From: rostovsamurai Date: Sun, 30 Mar 2025 00:04:08 +0300 Subject: [PATCH 1/3] =?UTF-8?q?=D0=9F=D1=80=D0=BE=D0=B5=D0=BA=D1=82=D0=BD?= =?UTF-8?q?=D0=B0=D1=8F=20=D1=80=D0=B0=D0=B1=D0=BE=D1=82=D0=B0=20=D0=BD?= =?UTF-8?q?=D0=BE=D0=BC=D0=B5=D1=80=203.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .idea/caches/deviceStreaming.xml | 607 +++++++++++++++++++++++++++++++ .idea/misc.xml | 3 +- src/main/kotlin/Main.kt | 8 +- 3 files changed, 614 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..9e9ba092 --- /dev/null +++ b/.idea/caches/deviceStreaming.xml @@ -0,0 +1,607 @@ + + + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml index 9c8e7400..3afe60ba 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -1,6 +1,5 @@ - - + \ No newline at end of file diff --git a/src/main/kotlin/Main.kt b/src/main/kotlin/Main.kt index aade54c5..264ee3f3 100644 --- a/src/main/kotlin/Main.kt +++ b/src/main/kotlin/Main.kt @@ -1,3 +1,7 @@ -fun main(args: Array) { - println("Hello World!") +import java.util.Scanner + +fun main() { + ArchiveList().start() + println("Спасибо что воспользовались приложением 'Заметки' :)") + } \ No newline at end of file From 48a6d6266c7aeea9d2ff9a513ad4d609913e561b Mon Sep 17 00:00:00 2001 From: rostovsamurai Date: Sun, 30 Mar 2025 00:04:52 +0300 Subject: [PATCH 2/3] =?UTF-8?q?=D0=9F=D1=80=D0=BE=D0=B5=D0=BA=D1=82=D0=BD?= =?UTF-8?q?=D0=B0=D1=8F=20=D1=80=D0=B0=D0=B1=D0=BE=D1=82=D0=B0=20=D0=BD?= =?UTF-8?q?=D0=BE=D0=BC=D0=B5=D1=80=203.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/kotlin/Archive.kt | 39 +++++++++++++++ src/main/kotlin/ArchiveList.kt | 39 +++++++++++++++ src/main/kotlin/Menu.kt | 87 ++++++++++++++++++++++++++++++++++ src/main/kotlin/Note.kt | 51 ++++++++++++++++++++ 4 files changed, 216 insertions(+) create mode 100644 src/main/kotlin/Archive.kt create mode 100644 src/main/kotlin/ArchiveList.kt create mode 100644 src/main/kotlin/Menu.kt create mode 100644 src/main/kotlin/Note.kt diff --git a/src/main/kotlin/Archive.kt b/src/main/kotlin/Archive.kt new file mode 100644 index 00000000..e8119093 --- /dev/null +++ b/src/main/kotlin/Archive.kt @@ -0,0 +1,39 @@ +class Archive(private val name: String) : Menu() { +override val menuTitle: String = "Архив $name" +override val menuItemName: String = "Заметка" + + override fun toString(): String { + return name + } + override fun add() { + println("Введите название заметки.") + getText() + ?.let { title -> + addItem(Note(title)) + println("Добавлена заметка \"$title\".") + } + ?: println("Нечитаемое название заметки.") + } + + override fun remove() { + println("Введите индекс заметки.") + getIndex() + ?.let { index -> + removeItem(index) + println("Заметка удалена.") + } + ?: println("Неверный индекс заметки.") + } + + override fun select() { + println("Введите индекс заметки.") + getIndex() + ?.let { index -> selectItem(index) } + ?: println("Неверный индекс заметки.") + } + + override fun show() { + println("Заметки:") + showItem() + } +} \ No newline at end of file diff --git a/src/main/kotlin/ArchiveList.kt b/src/main/kotlin/ArchiveList.kt new file mode 100644 index 00000000..f792a546 --- /dev/null +++ b/src/main/kotlin/ArchiveList.kt @@ -0,0 +1,39 @@ +class ArchiveList : Menu() { + override val menuTitle: String = "Архивный список" + override val menuItemName: String = "Архив" + + override fun toString(): String { + return "Архивный список" + } + + override fun add() { + println("Введите название архива.") + getText() + ?.let { title -> + addItem(Archive(title)) + println("Добавлен архив \"$title\".") + } + ?: println("Нечитаемое название архива.") + } + + override fun remove() { + println("Введите индекс архива.") + getIndex() + ?.let { index -> + removeItem(index) + println("Архив удален.") + } + ?: println("Неверный индекс архива.") + } + + override fun select() { + println("Введите индекс архива.") + getIndex() + ?.let { index -> selectItem(index) } + ?: println("Неверный индекс архива.") + } + override fun show() { + println("Архивы:") + showItem() + } +} \ 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..4c1d6670 --- /dev/null +++ b/src/main/kotlin/Menu.kt @@ -0,0 +1,87 @@ +import java.util.Scanner + +abstract class Menu { + private var list: MutableList = mutableListOf() + protected val scanner: Scanner = Scanner(System.`in`) + + open val menuTitle: String = "" + open val menuItemName:String = "" + + fun start() { + showMenu() + handleMenu() + } + + protected open fun showMenu() { + println("⚍⚍⚍⚍⚍⚍⚍⚍⚍⚍⚍⚍⚍⚍⚍⚍⚍") + println("$menuTitle:") + println("⚍⚍⚍⚍⚍⚍⚍⚍⚍⚍⚍⚍⚍⚍⚍⚍⚍") + println("1. Создать $menuItemName") + println("2. Убрать $menuItemName") + println("3. Выбрать $menuItemName") + println("4. Показать всё") + println("5. Выйти") + println("⚍⚍⚍⚍⚍⚍⚍⚍⚍⚍⚍⚍⚍⚍⚍⚍⚍") + println("Здесь могли быть рандомные цитаты при каждом запуске, но я пока не умею так делать :(.") + } + protected open fun handleMenu(){ + while (true) { + scanner.nextLine().toIntOrNull() + ?.let { value -> + when(value) { + 1 -> add() + 2 -> remove() + 3 -> select() + 4 -> show() + 5 -> return + else -> println("Неверная команда.") + } + showMenu() + } + ?: println("Введите число из списка") + } + } + abstract fun add() + + abstract fun remove() + + abstract fun select() + + abstract fun show() + + protected fun getText(): String? { + val data: String? + while (scanner.hasNext()) { + data = scanner.nextLine() + return data.ifEmpty { null } + } + return null + } + protected fun getIndex(): Int? { + getText() + ?.toIntOrNull() + ?.let { index -> + if ((index > 0) && (index <= list.size)) { + return index - 1 + } else { + return null + } + } + ?: return null + ?: return null + } + protected fun addItem(item: Menu) { + list.add(item) + } + protected fun removeItem(index: Int){ + list.removeAt(index) + } + protected fun selectItem(index: Int){ + list.elementAt(index).start() + } + protected fun showItem() { + var index = 0 + for (item in list) + println(" ${++index}: $item") + } +} \ 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..548ee6d1 --- /dev/null +++ b/src/main/kotlin/Note.kt @@ -0,0 +1,51 @@ + class Note(private val title: String, private var content: String = "") : Menu() { + override fun toString(): String { + return "Название: $title\n" + + "Текст: $content" + } + + override fun showMenu() { + println("⚍⚍⚍⚍⚍⚍⚍⚍⚍⚍⚍⚍⚍⚍⚍⚍⚍") + println("Заметка: $title") + println("⚍⚍⚍⚍⚍⚍⚍⚍⚍⚍⚍⚍⚍⚍⚍⚍⚍") + println("1. Показать текст своей заметки") + println("2. Записать текст в свою заметку") + println("3. Убрать текст в своей заметке") + println("4. Назад") + + } + + override fun handleMenu() { + while (true) { + scanner.nextLine().toIntOrNull() + ?.let { value -> + when(value) { + 1 -> show() + 2 -> add() + 3 -> remove() + 4 -> return + else -> println("Введите верное число") + } + showMenu() + } + ?: println("Введите число") + } + } + + override fun add() { + println("Введите текст заметки") + getText()?.let { text -> content = text } + } + + override fun remove() { + content = "" + println("Текст удален") + } + + override fun select() {} + + + override fun show() { + println(this) + } +} \ No newline at end of file From 6bb0d068f24cf80cba617f9bdddd0152bc0c843e Mon Sep 17 00:00:00 2001 From: Anatoly Alexeev Date: Fri, 25 Apr 2025 18:35:17 +0300 Subject: [PATCH 3/3] Update Readme.md --- Readme.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Readme.md b/Readme.md index 996ac25e..38498c51 100644 --- a/Readme.md +++ b/Readme.md @@ -1 +1 @@ -# Пустой репозиторий для работы с Kotlin кодом в Android Studio +# Проектная работа №3 ЯП