Skip to content
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

19_06 #164

Open
wants to merge 2 commits into
base: dev
Choose a base branch
from
Open

19_06 #164

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
3 changes: 1 addition & 2 deletions .idea/misc.xml

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

12 changes: 12 additions & 0 deletions src/main/kotlin/Arhive.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
class Archive(val name:String) {
override fun toString(): String {
return name
}

val noteList: MutableList<Note> = mutableListOf()
fun addNote(note: Note) {
noteList.add(noteList.size,note)
}


}
104 changes: 104 additions & 0 deletions src/main/kotlin/ArhiveCreate.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
import java.util.Scanner

class ArhiveCreate {
val archiveList = mutableListOf<Archive>()
private var scanner = Scanner(System.`in`)
var noteList: MutableList<Note> = mutableListOf()
fun printMenu() {
while (true){

getSize(archiveList,"СОЗДАНИЕ АРХИВА\nВведите номер архива либо \n0 - Создать архив ")

val command = switch(archiveList.size)

if (command == -100) {
println("Вы вышли из приложения")
break
}
if (command == 0) {
val archiveName=nameInput("Введите название архива: ")
val newArhive =Archive(name=archiveName)
archiveList.add(newArhive)
println("Архив добавлен: $archiveName")

} else {
while (true){
val archive = archiveList[command - 1]
noteList=archive.noteList

getSize(noteList,"СОЗДАНИЕ ЗАМЕТКИ\nВведите номер заметки либо \n0 - Создать заметку ")
val commandNote=switch(noteList.size)
when(commandNote) {
0 -> {
val noteName = nameInput("Введите заголовок заметки: ")
val noteInfo = nameInput("Введите содержание заметки: ")
archive.addNote(Note(noteName, noteInfo))
println("Заметка добавлена: $noteName") }

-100->break

else->println(noteList[commandNote-1].infoOut())
}
}
}
}

}





fun nameInput(string: String): String {
while (true) {
println(string)
val name=getCommand()
if (name.isNotEmpty()) {
return name
} else {
println("Некорректный ввод, попробуйте снова.")
}
}
}
fun isInt(str: String) = try {
str.toInt()
true
} catch (e: NumberFormatException) {
false
}
open fun getCommand(): String {
return scanner.nextLine()
}

fun switch(size:Int):Int{
var command=""
while (true) {
command=getCommand()
if(!isInt(command)) {
println("Ошибка: надо ввести целое число!")
continue}
if(command.toInt() > (size +1)) {
println("Ошибка: такого пункта меню нет. Попробуйте еще раз!")
continue
}
if(command.toInt() <0) {
println("Ошибка: число должно быть целым положительным!")
continue
}
if (command.toInt() == size + 1) {
return -100
break
}
else {
break
}
}
return command.toInt()
}
fun <T> getSize(t: MutableList<T>,string: String) {
println(string)
for (i in 0..t.size-1){
println("${i + 1} - ${t.get(i)}")}
println("${t.size + 1} - Выход")
}
}
6 changes: 5 additions & 1 deletion src/main/kotlin/Main.kt
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
import java.util.Scanner

fun main(args: Array<String>) {
println("Hello World!")
println("Приложение список заметок")
val arhiveCreate=ArhiveCreate()
println(arhiveCreate.printMenu())
}
11 changes: 11 additions & 0 deletions src/main/kotlin/Note.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
open class Note(val name: String, val info:String) {

override fun toString(): String {

return name
}
fun infoOut(): String {

return "СОДЕРЖИМОЕ ЗАМЕТКИ с названием: $name\n$info"
}
}