package ListAAA
import scala.collection.mutable.ListBuffer
class Book(var bookName: String, var author: String, val price: Double) {}
object list3 {
def main(args: Array[String]): Unit = {
val bookList: ListBuffer[Book] = ListBuffer()
val book1 = new Book("西游记", "吴承恩", 50.2)
bookList += book1
val book2 = new Book("三国演义", "罗贯中", 54.2)
bookList += book2
val book4 = new Book("红楼梦", "曹雪芹", 49.8)
bookList += book4
val book5 = new Book("水浒传", "施耐庵", 48.5)
bookList += book5
val book6 = new Book("朝花夕拾", "鲁迅", 32.0)
bookList += book6
val book7 = new Book("呐喊", "鲁迅", 29.9)
bookList += book7
val book3 = new Book("凡人修仙传", "忘语", 30.0)
bookList.prepend(book3)
bookList.insert(2, new Book("平凡的世界", "路遥", 50.0))
val targetBookName = "平凡的世界"
val isExist = bookList.exists(book => book.bookName == targetBookName)
println(s"图书《$targetBookName》是否存在:$isExist")
bookList.remove(3)
val sortedBookList = bookList.sortWith((a, b) => a.price > b.price)
println("\n按价格从高到低排序后的图书列表:")
sortedBookList.foreach(book => {
println(s"书名:${book.bookName}, 作者:${book.author}, 价格:${book.price}元")
})
val totalAmount = sortedBookList.map(_.price).sum
println(s"\n全部图书的总金额:${totalAmount}元")
}
}