/**
* 查询--根据图书名称查询图书信息
* @param name
*/
public
Book query(String name){
for
(
int
i =
0
; i < list.size(); i++) {
Book book = list.get(i);
if
(name.equals(book.getName())){
System.out.println(book);
return
book;
}
}
return
null
;
}
/**
* 展示所有图书信息
*/
public
void
showAll(){
for
(
int
i =
0
; i < list.size(); i++) {
System.out.println(list.get(i));
}
}
/**
* 按照价格降序排序
*/
public
void
sort(){
Collections.sort(list,
new
Comparator<Book>() {
@Override
public
int
compare(Book o1, Book o2) {
return
-(
int
)(o1.getPrice()-o1.getPrice());
}
});
}
}