Skip to content

Приложение работает #247

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
615 changes: 615 additions & 0 deletions .idea/caches/deviceStreaming.xml

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

40 changes: 40 additions & 0 deletions src/main/kotlin/Archive.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
class Archive(val name: String) {
private val notes = mutableListOf<Note>()

fun showMenu() {
while (true) {
println("Список заметок в архиве '$name':")
println("0. Создать заметку")
for ((index, note) in notes.withIndex()) {
println("${index + 1}. ${note.title}")
}
println("${notes.size + 1}. Назад")
val note = NotesApp()
val choice = note.readUserInput()
when (choice) {
0 -> createNote()
in 1..notes.size -> notes[choice - 1].show()
notes.size + 1 -> break
else -> println("Неверный ввод. Попробуйте снова.")
}
}
}


private fun createNote() {
println("Введите заголовок заметки:")
val title = readLine()?.trim()
if (title.isNullOrEmpty()) {
println("Заголовок не может быть пустым.")
return
}
println("Введите текст заметки:")
val content = readLine()?.trim()
if (content.isNullOrEmpty()) {
println("Текст заметки не может быть пустым.")
return
}
notes.add(Note(title, content))
println("Заметка '$title' создана.")
}
}
7 changes: 4 additions & 3 deletions src/main/kotlin/Main.kt
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
fun main(args: Array<String>) {
println("Hello World!")
}
fun main() {
val app = NotesApp()
app.start()
}
27 changes: 27 additions & 0 deletions src/main/kotlin/MenuManager.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import java.util.Scanner

class MenuManager(private val scanner: Scanner) {

fun showMenu(menuItems: List<Pair<String, () -> Unit>>) {
while (true) {
println("Выберите пункт меню:")
menuItems.forEachIndexed { index, item ->
println("$index. ${item.first}")
}
println("Введите номер пункта (или 'выход' для выхода):")
val input = scanner.nextLine()

if (input.lowercase() == "выход") {
println("Выход из программы.")
return
}

val index = input.toIntOrNull()
if (index != null && index in menuItems.indices) {
menuItems[index].second()
} else {
println("Неверный ввод. Пожалуйста, введите номер пункта.")
}
}
}
}
8 changes: 8 additions & 0 deletions src/main/kotlin/Note.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
class Note(val title: String, private val content: String) {
fun show() {
println("Заголовок: $title")
println("Содержание: $content")
println("Нажмите Enter, чтобы вернуться.")
readLine()
}
}
43 changes: 43 additions & 0 deletions src/main/kotlin/NotesApp.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
class NotesApp {
private val archives = mutableListOf<Archive>()

fun start() {
while (true) {
println("Список архивов:")
println("0. Создать архив")
for ((index, archive) in archives.withIndex()) {
println("${index + 1}. ${archive.name}")
}
println("${archives.size + 1}. Выход")

val choice = readUserInput()
when (choice) {
0 -> createArchive()
in 1..archives.size -> archives[choice - 1].showMenu()
archives.size + 1 -> break
else -> println("Неверный ввод. Попробуйте снова.")
}
}
}

private fun createArchive() {
println("Введите имя архива:")
val name = readLine()?.trim()
if (name.isNullOrEmpty()) {
println("Имя архива не может быть пустым.")
return
}
archives.add(Archive(name))
println("Архив '$name' создан.")
}

fun readUserInput(): Int {
while (true) {
val input = readLine()
if (input != null && input.toIntOrNull() != null) {
return input.toInt()
}
println("Введите число.")
}
}
}