diff --git a/.idea/caches/deviceStreaming.xml b/.idea/caches/deviceStreaming.xml new file mode 100644 index 00000000..61a0a4a3 --- /dev/null +++ b/.idea/caches/deviceStreaming.xml @@ -0,0 +1,679 @@ + + + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml index 9c8e7400..1945ce5f 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..ded6e878 --- /dev/null +++ b/src/main/kotlin/Archive.kt @@ -0,0 +1,22 @@ + +data class Archive (val name:String){ + + private val notesList = mutableListOf() + + fun createNote() { + println("Укажите название заметки:") + val nameNote = CheckingDataEntry().inputStringName() + println("Укажите содержание заметки:") + val contentNote = CheckingDataEntry().inputStringName() + notesList.add(Note(nameNote, contentNote)) + println("Заметка '$nameNote' добавлена.") + } + + fun displayNotes() { + if (CheckingDataEntry().checkingCollection(notesList)) { + notesList.forEachIndexed {index, note -> println("${index + 1} - ${note.name}: ${note.content}") } + } + } + +} + diff --git a/src/main/kotlin/CheckingDataEntry.kt b/src/main/kotlin/CheckingDataEntry.kt new file mode 100644 index 00000000..528fec7e --- /dev/null +++ b/src/main/kotlin/CheckingDataEntry.kt @@ -0,0 +1,40 @@ +import java.util.Scanner + +class CheckingDataEntry { + + val scanner : Scanner = Scanner(System.`in`) + + fun readInput():String{ + return scanner.nextLine().trim() + } + + fun resultInputInt(result:String?) : Int{ + var intInput = result?.toIntOrNull() + while (intInput == null){ + print("Введенное значение не число. Повторите ввод:") + intInput = readLine()?.toIntOrNull() + } + return intInput + } + + fun inputStringName() :String{ + var stringInput = readlnOrNull()?: "" + + while (stringInput.length == 0){ + print("Текст не может быть пустым. Повторите ввод:") + stringInput = readlnOrNull()?: "" + } + return stringInput + } + + fun checkingCollection(list: MutableList):Boolean{ + if (list.isEmpty()) { + println("---Список данных пуст---") + return false} + return true + } + + fun checking():Int{ + return resultInputInt(readInput()) + } +} \ No newline at end of file diff --git a/src/main/kotlin/Main.kt b/src/main/kotlin/Main.kt index aade54c5..2243d126 100644 --- a/src/main/kotlin/Main.kt +++ b/src/main/kotlin/Main.kt @@ -1,3 +1,5 @@ -fun main(args: Array) { - println("Hello World!") -} \ No newline at end of file + + +fun main() { + Menu().viewMenu() +} diff --git a/src/main/kotlin/Menu.kt b/src/main/kotlin/Menu.kt new file mode 100644 index 00000000..43bea475 --- /dev/null +++ b/src/main/kotlin/Menu.kt @@ -0,0 +1,82 @@ +import kotlin.system.exitProcess + +class Menu () { + + private val listArchive = mutableListOf() + + private val textItemMenu:String = "Укажите пункт меню: " + private val textErrorItemMenu:String = "Данный пункт меню отсутствует. Попробуйте еще раз:" + + fun viewMenu() { + while (true) { + println("*** ГЛАВНОЕ МЕНЮ ***") + println("1. Создать архив") + println("2. Просмотреть архивы") + println("0. Выход") + + print(textItemMenu) + + while (true){ + when (CheckingDataEntry().checking()) { + 0 -> exitProcess(0) + 1 -> createArchive() + 2 -> showArchive() + else -> print(textErrorItemMenu) + } + } + } + } + + private fun createArchive() { + println("Укажите название архива:") + val nameArchive = CheckingDataEntry().inputStringName() + + listArchive.add(Archive(nameArchive)) + println("Создан архив '$nameArchive'.") + } + + private fun showArchive() { + if (CheckingDataEntry().checkingCollection(listArchive)) { + listArchive.forEachIndexed{ index, archive -> + println("${index + 1}. ${archive.name}") + } + selectArchive() + } + } + + private fun selectArchive() { + print("Выберите 'элемент' для просмотра (или 0 - для возврата):") + val res = CheckingDataEntry().checking() + + when(res) { + 0 -> viewMenu() + else -> + if (res >= 1) { + val numberArchive = res - 1 + if (listArchive.elementAtOrNull(numberArchive) != null) { + val archive = listArchive[numberArchive] + menuArchive(archive) + } + else println("Указанный элемент отсутствует") + } + } + } + + private fun menuArchive(archive: Archive) { + while (true) { + println("Архив '${archive.name}':") + println("1. Добавить заметку") + println("2. Просмотреть заметки") + println("0. Возврат") + + print(textItemMenu) + when (CheckingDataEntry().checking()) { + 0 -> showArchive() + 1 -> archive.createNote() + 2 -> archive.displayNotes() + else -> print(textErrorItemMenu) + } + } + } + +} \ 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..340c6e35 --- /dev/null +++ b/src/main/kotlin/Note.kt @@ -0,0 +1,2 @@ + +data class Note(val name:String, val content:String) {} \ No newline at end of file