forked from Yandex-Practicum/Kotlin-Module-Project
-
Notifications
You must be signed in to change notification settings - Fork 0
Заметки #1
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
SERYOGA-cloud
wants to merge
3
commits into
main
Choose a base branch
from
dev
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Заметки #1
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1 @@ | ||
| # Пустой репозиторий для работы с Kotlin кодом в Android Studio | ||
| # Заметки |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| class Archive(val name: String) { | ||
| var noteList = mutableListOf<Note>() | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,4 @@ | ||
| fun main(args: Array<String>) { | ||
| println("Hello World!") | ||
| } | ||
| val notesApp = NotesApp() | ||
| notesApp.start() | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| class Note(val text: String) { | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,100 @@ | ||
| import java.util.Scanner | ||
|
|
||
| class NotesApp { | ||
| var archives = mutableListOf<Archive>() | ||
| var scanner = Scanner(System.`in`) | ||
|
|
||
| fun start() { | ||
| while (true) { | ||
| println("1. Создать архив") | ||
| println("2. Посмотреть архивы") | ||
| println("3. Выход") | ||
| when(scanner.nextLine().toIntOrNull()){ | ||
| 1 -> createArchive() | ||
| 2 -> viewArchives() | ||
| 3 -> {scanner.close(); return} | ||
| else -> println("Неверный ввод. Пожалуйста, введите число от 1 до 3!") | ||
| } | ||
| } | ||
| } | ||
|
|
||
| fun createArchive() { | ||
| println("Придумайте название архива: ") | ||
| val nameArchive = scanner.nextLine() | ||
| if (nameArchive.isBlank()){ | ||
| println("Название архива не может быть пустым") | ||
| return | ||
| } | ||
| archives.add(Archive(nameArchive)) | ||
| println("Архив $nameArchive создан!") | ||
| } | ||
|
|
||
| fun viewArchives() { | ||
| if (archives.isEmpty()){ | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Здесь и в методе viewNotes() можно использовать when вместо цепочки if |
||
| println("Архив пуст ~~(;-;)~~") | ||
| return | ||
| } | ||
| println("Список архивов") | ||
| archives.forEachIndexed { index, archive -> println("${index + 1}. ${archive.name}") } | ||
| println("0. Назад") | ||
| val inx = scanner.nextLine().toIntOrNull() | ||
| if (inx == null || (inx > archives.size)) { // Здесь надо поставить знак > вместо !in | ||
| println("Неверный ввод. Пожалуйста, введите число от 0 до ${archives.size }.") | ||
| return | ||
| } | ||
| if (inx == 0){ | ||
| return | ||
| } | ||
| viewArchive(archives[inx - 1]) | ||
| } | ||
|
|
||
| fun viewArchive(archive: Archive) { | ||
| while (true) { | ||
| println("Выберите действие в архиве '${archive.name}':") | ||
| println("1. Создать заметку") | ||
| println("2. Открыть заметки") | ||
| println("3. Назад") | ||
| when (scanner.nextLine().toIntOrNull()) { | ||
| 1 -> createNote(archive) | ||
| 2 -> viewNotes(archive) | ||
| 3 -> return | ||
| else -> println("Неверный ввод. Пожалуйста, введите число от 1 до 3.") | ||
| } | ||
| } | ||
| } | ||
|
|
||
| fun createNote(archive: Archive) { | ||
| println("Введите текст: ") | ||
| val textNote = scanner.nextLine() | ||
| if (textNote.isBlank()){ | ||
| println("Название заметки не может быть пустым") | ||
| return | ||
| } | ||
| archive.noteList.add(Note(textNote)) | ||
| println("Заметка создана!\nДля архива ${archive.name}") | ||
| } | ||
|
|
||
| fun viewNotes(archive: Archive) { | ||
| if (archive.noteList.isEmpty()){ | ||
| println("Заметок нет ~~(;-;)~~") | ||
| return | ||
| } | ||
| println("Список заметок: ") | ||
| archive.noteList.forEachIndexed { index, note -> println("${index + 1}. ${note.text}") } | ||
| println("0. Назад") | ||
| val viewNoteIndex = scanner.nextLine().toIntOrNull() | ||
| if(viewNoteIndex == null || (viewNoteIndex > archive.noteList.size)){ // Здесь надо поставить знак > вместо !in | ||
| println("Неверный ввод. Пожалуйста, введите число от 0 до ${archive.noteList.size}.") | ||
| return | ||
| } | ||
| if (viewNoteIndex == 0) { | ||
| return | ||
| } | ||
| viewNote(archive.noteList[viewNoteIndex - 1]) | ||
| } | ||
|
|
||
| fun viewNote(note: Note) { | ||
| println(note.text) | ||
| } | ||
|
|
||
| } | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Лучше сделать поля приватными