You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
50 lines
1.3 KiB
50 lines
1.3 KiB
package jichuti1;
|
|
|
|
import java.time.LocalDate;
|
|
import java.util.ArrayList;
|
|
import java.util.List;
|
|
|
|
/**
|
|
* 读者类,包含预约功能
|
|
*/
|
|
public class Reader {
|
|
private String readerId; // 读者ID
|
|
private String name; // 读者姓名
|
|
private List<Reservation> reservations; // 预约列表
|
|
|
|
public Reader(String readerId, String name) {
|
|
this.readerId = readerId;
|
|
this.name = name;
|
|
this.reservations = new ArrayList<>();
|
|
}
|
|
|
|
/**
|
|
* 预约图书功能
|
|
* @param book 要预约的图书
|
|
* @param date 预约日期
|
|
* @return 预约结果
|
|
*/
|
|
public Reservation reserveBook(Book book, LocalDate date) {
|
|
if (!book.isAvailable()) {
|
|
Reservation reservation = new Reservation(
|
|
"RES" + System.currentTimeMillis(),
|
|
this,
|
|
book,
|
|
date
|
|
);
|
|
reservations.add(reservation);
|
|
return reservation;
|
|
}
|
|
return null;
|
|
}
|
|
|
|
// 取消预约
|
|
public void cancelReservation(Reservation reservation) {
|
|
reservations.remove(reservation);
|
|
}
|
|
|
|
// getter
|
|
public String getReaderId() { return readerId; }
|
|
public String getName() { return name; }
|
|
}
|