private fun updateBook() {
        println("Pick a book by its number to update:")
        viewBooks(false)
        println("\nSelection: ")
        val bookSelection = try {
            books[readLine()!!.toInt() - 1]
        } catch (e: Exception) {
            println("Invalid selection! Aborting..")
            return
        }
        println("\nSelected:\n$bookSelection.\n\nChoose a variable to update:")
        printBookVariables()
        println("\nSelection: ")
        val enumSelection = try {
            readLine()!!.toInt()
        } catch (e: Exception) {
            println("Invalid selection! Aborting..")
            return
        }

        val selected = BookVariables.values().associateBy(BookVariables::id)[enumSelection]
        println("\nSelected modifier:\n$selected\n\nType a new ${selected.toString().toLowerCase()}:")
        try {
            val newValue = readLine()!!
            if (newValue.isBlank()) {
                println("Modification can't be empty! Aborting..")
                return
            }
            when (enumSelection) {
                BookVariables.TITLE.id -> bookSelection.title = newValue
                BookVariables.AUTHOR.id -> bookSelection.author = newValue
                BookVariables.PUBLICATION_YEAR.id -> {
                    if (newValue.toInt() <= 1600) {
                        println("Publication year is too old! Aborting..")
                        return
                    }
                    bookSelection.publicationYear = newValue.toInt()
                }
                BookVariables.NUMBER_OF_PAGES.id -> {
                    if (newValue.toInt() <= 0) {
                        println("There must be at least one page! Aborting..")
                        return
                    }
                    bookSelection.numberOfPages = newValue.toInt()
                }
                BookVariables.ISBN_NUMBER.id -> bookSelection.isbn = newValue.toLong()
            }
        } catch (e: NumberFormatException) {
            println("Invalid selection! Aborting..")
            return
        }
        println("\nUpdated book info:\n$bookSelection")
    }

    private fun deleteBook() {
        println("Pick a book by its number to delete:")
        viewBooks(false)
        println("\nSelection: ")
        val bookSelection = try {
            books[readLine()!!.toInt() - 1]
        } catch (e: Exception) {
            println("Invalid selection! Aborting..")
            return
        }
        books.remove(bookSelection)
        println("Book deleted!")
    }

    private fun viewBookWithMostPages() {
        val find = books.maxByOrNull { it.numberOfPages }
        if (find == null) {
            println("No books found! Aborting..")
            return
        }
        println("Book with most pages:\n${find.title} (Pages: ${find.numberOfPages})")
    }

    private fun viewBookWithLeastPages() {
        val find = books.minByOrNull { it.numberOfPages }
        if (find == null) {
            println("No books found! Aborting..")
            return
        }
        println("Book with least pages:\n${find.title} (Pages: ${find.numberOfPages})")
    }

    private fun viewBooksPagesAboveOrEqual(number: Int) {
        println("Books with pages above or equal to $number:")
        val find = books.filter { it.numberOfPages >= number }
        viewBooks(false, find)
    }

    private fun viewBooksPagesBelow(number: Int) {
        println("Books with pages below $number:")
        val find = books.filter { it.numberOfPages < number }
        viewBooks(false, find)
    }

    private fun viewBooksPagesBetweenInclusive(min: Int, max: Int) {
        println("Books with pages between $min and $max:")
        val find = books.filter { it.numberOfPages in min..max }
        viewBooks(false, find)
    }

//    fun viewBooksWithPagesInRange(books: MutableList<Book>, range: IntRange = 0..Int.MAX_VALUE) {
//        val tempBooksList = mutableListOf<Book>()
//        println("Books with pages between ${range.first} and ${range.last}: ")
//        for (book in books) {
//            if(book.numberOfPages in range) {
//                tempBooksList.add(book)
//            }
//        }
//        printBooks(tempBooksList, false)
//    }
}

class Book(
    var title: String,
    var author: String,
    var publicationYear: Int,
    var numberOfPages: Int,
    var isbn: Long
) {
    override fun toString(): String {
        return "$title, $author, $publicationYear, $numberOfPages, https://biblio.com/$isbn"
    }

    fun toTab(): String {
        return "$title\t$author\t$publicationYear\t$numberOfPages\t$isbn"
    }
}

Kotlin相关代码片段

run function in companion object kotlin

kotlin compiler

preety print a data class in kotlin

kotlin time taken

check internet reachable android kotlin

check network status android kotlin

check internet available on android kotlin

how to read a exel file in kotlin

square root in kotlin

convert list to string kotlin

splash screen in react native kotlin

view elevation android kotlin

abstraction in kotlin

singleton object in kotlin

round up in kotlin

keyboard options jetpack compose kotlin

Unresolved reference: Transformations

Fibonacci using an infinite sequence

options menu without an action bar android kotlin

kotlin when statement

Kotlin okhttp

compose, kotlin

import a external jar gradle kotlin

use viewbinding android

check if string is url android kotlin

inherit from button kotlin

inherit from view kotlin

give me above code in kotlin

check jks password

customSpinnerAdapter

Jetpack Compose make image fullsize

kotlin spring boot run code after component init

update kotlin gradle plugin

dictionary in kotlin

compare two numeric string values

kotlin create function

send method as parameter kotlin

pass class as parameter kotlin

set text to edittext android kotlin

minus kotlin

kotlin pair triple quadruple

how to validate email kotlin

Jetpack Compose custom switch

get string always defaulting

Jetpack Compose one sided stroke

android studio int to long

Android Kotlin Compose bottom bar

was ist bei der if anweisung dreimal === in kotlin

mapstruct to dto all fields null

set margins kotlin

kotlin serialization ignore field

kotlin interview questions android

kotlin list to string with separator

kotlin kapt plugin android

kotlin operators

kotlin variables

kotlin data types

kotlin comments

kotlin output

kotlin hello world 1.3

kotlin kotlin ide

can by lazy used with var in kotlin

open link in browser kotlin

how to kotlin get last string

how to write event calendar android kotlin

how to get .push string firebase kotlin

how to play background music in kotlin

room db android default value

Retrofit With MVI Architecture using Kotlin

viewbinding

bootstrap5 columns

check if variable is initialized kotlin

kotlin find max value in list of objects

kotlin time hours

how to create kotlin project in android studio

recyclerview kotlin grid layout

android studio change activity kotlin

create viewmodel instance android kotlin

context in kotlin

android kotlin local currency code and symbol