feat(java-lesson): java实验3-实现图书租阅管理系统

- 新增 Book、RentBook、VIPReader 类- 实现 RentBookManage 和 RentBookManagenew 类的图书管理功能
- 添加 PayException 异常类和 DecF 工具类
- 编写测试类 Test、TestRentBookManage 和 TestRentBookManageNew
This commit is contained in:
dev_xulongjin 2025-04-14 10:19:58 +08:00
parent 86b4d22c7d
commit a960428156
14 changed files with 888 additions and 0 deletions

17
java-lesson/pom.xml Normal file
View File

@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>cn.vscoder</groupId>
<artifactId>java-lesson</artifactId>
<version>1.0-SNAPSHOT</version>
<properties>
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
</project>

View File

@ -0,0 +1,52 @@
package cn.vscoder.experiment_3.book;
public class Book {
/* 定义类的5个成员变量书号、书名、作者、出版社、定价*/
public String ISBN; //存储国际标准书号
public String bookName; //存储书名
public String author; //存储作者
public String publisher; //存储出版社
private double price; //存储书的定价
public Book(String ISBN, String bookName, String author, String publisher, double price) {
this.ISBN = ISBN;
this.bookName = bookName;
this.author = author;
this.publisher = publisher;
this.price = price;
}
public String getISBN() {
return ISBN;
}
public String getBookName() {
return bookName;
}
public String getAuthor() {
return author;
}
public String getPublisher() {
return publisher;
}
public double getPrice() {
return price;
}
public void setPrice(double price) {
this.price = price;
}
@Override
public String toString() {
return "图书信息:" +
"ISBN='" + ISBN + '\'' +
", 书名='" + bookName + '\'' +
", 作者='" + author + '\'' +
", 出版社='" + publisher + '\'' +
", 定价=" + price;
}
}

View File

@ -0,0 +1,35 @@
package cn.vscoder.experiment_3.book;
public class RentBook extends Book {
private String bookNo;//入库编号
private boolean state;//是否可借 true:可借
public RentBook(String ISBN, String bookName, String author, String publisher, double price, String bookNo) {
super(ISBN, bookName, author, publisher, price);
this.bookNo = bookNo;
state = true;//默认可借
}
public String getBookNo() {
return bookNo;
}
public void setBookNo(String bookNo) {
this.bookNo = bookNo;
}
public boolean isState() {
return state;
}
public void setState(boolean state) {
this.state = state;
}
@Override
public String toString() {
return super.toString() +
",入库编号='" + bookNo + '\'' +
", 是否可借=" + state;
}
}

View File

@ -0,0 +1,23 @@
package cn.vscoder.experiment_3.common;
/* 自定义一个对double型数据的小数点只显示2位的专用类 */
import java.text.NumberFormat;
import java.math.BigDecimal;
public class DecF
{
public static String DecS(Double x) //方法返回保留两位小数的字符串
{
NumberFormat df = NumberFormat.getNumberInstance();
df.setMaximumFractionDigits(2);
return df.format(x);
}
public static double DecD(Double x) //方法返回保留两位小数的Double值
{
x = new BigDecimal(x)
.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue();
return x;
}
}

View File

@ -0,0 +1,14 @@
package cn.vscoder.experiment_3.common;
public class PayException extends Exception {
String s;
public PayException() {
s = "余额不足以支付租金。";
}
//输出异常信息
public String toString() {
return s;
}
}

View File

@ -0,0 +1,7 @@
package cn.vscoder.experiment_3.common;
public interface Promotion {
static final int promtpoints = 1000;
abstract void promotion(String level);
}

View File

@ -0,0 +1,69 @@
package cn.vscoder.experiment_3.reader;
public class Reader {
public int readerID;
protected String readerName;
protected String readerPwd;
protected double balance;
private static int nextReaderID;
static{
nextReaderID=10001;
}
public Reader() {
readerID=nextReaderID++;
readerName="";
readerPwd="666666";
balance=0;
}
public Reader(String readerName) {
this();
this.readerName = readerName;
}
public int getReaderID() {
return readerID;
}
public String getReaderName() {
return readerName;
}
public String getReaderPwd() {
return readerPwd;
}
public double getBalance() {
return balance;
}
//修改密码密码必须为6位
public void changePwd(String oldPwd,String newPwd){
if (oldPwd.equals(this.readerPwd)){
if (newPwd.length()==6){
this.readerPwd=newPwd;
System.out.println("密码修改成功!");
}else{
System.out.println("密码必须为6位");
}
}
}
//充值功能充值不能小于0
public void setBalance(double balance) {//充值
if (balance<0){
System.out.println("充值金额不能小于0");
}else {
this.balance += balance;}
}
@Override
public String toString() {
return "读者信息:" +
"readerID=" + readerID +
", 读者姓名='" + readerName + '\'' +
", 密码='" + readerPwd + '\'' +
", 余额=" + balance ;
}
}

View File

@ -0,0 +1,94 @@
package cn.vscoder.experiment_3.reader;
import cn.vscoder.experiment_3.common.PayException;
import cn.vscoder.experiment_3.common.Promotion;
public class VIPReader extends Reader implements Promotion {
private String readerGrade;//读者级别
private double percent;//折扣率
private int bonusPoints;//积分
public VIPReader(String readerName, String readerGrade) {
super(readerName);
this.readerGrade = readerGrade;
setPercent();//设置折扣率
bonusPoints = 0;
}
public String getReaderGrade() {
return readerGrade;
}
public void setReaderGrade(String readerGrade) {
this.readerGrade = readerGrade;
}
public double getPercent() {
return percent;
}
public void setPercent() {
if (readerGrade.equals("VIP")) {
this.percent = 0.8;//8折
} else if (readerGrade.equals("普通会员")) {
this.percent = 0.9;//9折
} else {//非会员
this.percent = 1;//不打折
}
}
public boolean payRent(double money) throws PayException {//支付
// if (this.getBalance() >= money) {
// this.balance = this.balance - money;
// return true;
// } else {
// System.out.println("余额不足,请及时充值!");
// return false;
// }
if (this.balance < money) {
throw new PayException(); //当余额不足支付租金时抛出支付异常
} else {
balance = balance - money;
return true;
}
}
public int getBonusPoints() {
return bonusPoints;
}
public void setBonusPoints(int bonusPoints) {//积分
this.bonusPoints += bonusPoints;
}
@Override
public String toString() {
return super.toString() +
",读者级别='" + readerGrade + '\'' +
", 折扣率=" + percent +
", 积分=" + bonusPoints;
}
@Override
public void promotion(String level) //实现接口中的抽象方法
{
if (this.getBonusPoints() >= promtpoints) //如果会员积分超过晋级标准
{
switch (level) {
case "VIP":
this.balance += 10;
break; //对VIP会员1000积分返利10元
case "普通会员":
this.readerGrade = "VIP";
break; //对普通会员达到1000积分则晋级为VIP会员
case "非会员":
this.readerGrade = "普通会员";
break;//非会员达到1000积分则晋级为普通会员
}
bonusPoints -= promtpoints; //晋级后会员积分-晋级标准分
} else
readerGrade = level; //积分不达标身份不变
setPercent(); //调用设置折扣的方法
}
}

View File

@ -0,0 +1,163 @@
package cn.vscoder.experiment_3.rent;
import cn.vscoder.experiment_3.book.RentBook;
import cn.vscoder.experiment_3.common.PayException;
import cn.vscoder.experiment_3.reader.VIPReader;
import java.util.ArrayList;
import java.util.LinkedList;
public class RentBookManage {
//租阅期限deadTime
int deadTime = 30;
double normalRent = 0.5;//正常租阅费用
double delayRent = 1.0;//超期租阅费用
int rentDays;
double rent;//租阅费用
public ArrayList<VIPReader> readerlist;//读者列表
LinkedList<RentBook> booklist;//图书列表
ArrayList<String> rentlist;//租阅记录
VIPReader renter;//借阅者
RentBook rentbook;
public RentBookManage() {//创建空的列表
booklist = new LinkedList<>();
readerlist = new ArrayList<>();
rentlist = new ArrayList<>();
}
//图书管理相关功能添加图书删除图书打印图书列表修改图书价格查找图书
public void addBook(RentBook rentBook) {
booklist.add(rentBook);
}
public void addBook(String isbn, String bookname, String author, String publisher, double price, String inNo) {
booklist.add(new RentBook(isbn, bookname, author, publisher, price, inNo));
}
public void addBook(int i, RentBook rentBook) {//指定位置添加图书
booklist.add(i - 1, rentBook);
}
public RentBook searchBook(String bookName) {//根据书名查找图书
for (int j = 0; j < booklist.size(); j++) {
if (booklist.get(j).getBookName().equals(bookName)) {
System.out.println(booklist.get(j));
return booklist.get(j);
}
}
System.out.println("您要查找的图书:" + bookName + "不存在!");
return null;
}
public void editBook(String bookName, double newprice) {
for (int j = 0; j < booklist.size(); j++) {
if (booklist.get(j).getBookName().equals(bookName)) {
booklist.get(j).setPrice(newprice);
System.out.println(booklist.get(j));
return;
}
}
System.out.println("您要查找的图书:" + bookName + "不存在!");
}
public void deleteBook(String bookName) {
for (int j = 0; j < booklist.size(); j++) {
if (booklist.get(j).getBookName().equals(bookName)) {
booklist.remove(j);
System.out.println("删除" + bookName + "成功!");
return;
}
}
System.out.println("您要删除的图书:" + bookName + "不存在!");
}
public void displayAllBooks() {
for (RentBook rentBook : booklist) {
System.out.println(rentBook);
}
}
//读者添加读者显示所有读者
public void addReader(String name, String grade) {
readerlist.add(new VIPReader(name, grade));
}
public void addReader(VIPReader vipReader) {
readerlist.add(vipReader);
}
public void displayAllReaders() {
for (VIPReader vipReader : readerlist) {
System.out.println(vipReader);
}
}
//计算租金
public double setRent() {
if (rentDays <= deadTime) {
rent = rentDays * normalRent * renter.getPercent();
} else {
rent = ((rentDays - deadTime) * delayRent + normalRent * deadTime) * renter.getPercent();
}
return rent;
}
//支付租金
public boolean renting() throws PayException {
setRent();
if (renter.payRent(rent)) {
System.out.println(renter.getReaderName() + "支付租金:" + rent + "成功!");
return true;
} else {
System.out.println(renter.getReaderName() + "的账号余额为:" + renter.getBalance() + "不足以支付租金" + rent);
return false;
}
}
//租阅功能
public boolean rentBook(VIPReader vr, RentBook bk, int days) throws PayException {
rentbook = bk;
renter = vr;
rentDays = days;
if (renting()) {
renter.setBonusPoints(rentDays);//给借阅者积分
rentlist.add("读者:" + renter.getReaderName() + "\t读者等级" + renter.getReaderGrade() + "\t借阅图书为" + bk.getBookName() + "\t租书天数" + rentDays + "\t租金:" + rent + "读者当前积分" + renter.getBonusPoints() + "\t读者账户余额" + renter.getBalance());
return true;
} else {
System.out.println("支付失败");
return false;
}
}
//展示借阅记录
public void printRentlist() {
for (String str : rentlist) {
System.out.println(str);
}
}
public double getNormalRent() {
return normalRent;
}
public void setNormalRent(double normalRent) {
this.normalRent = normalRent;
}
public double getDelayRent() {
return delayRent;
}
public void setDelayRent(double delayRent) {
this.delayRent = delayRent;
}
public int getDeadTime() {
return deadTime;
}
}

View File

@ -0,0 +1,172 @@
package cn.vscoder.experiment_3.rent;
/* 第3-6题是RentBookManage修改后的图书租赁信息管理类 */
import cn.vscoder.experiment_3.book.RentBook; // 引入book包中的RentBook类
import cn.vscoder.experiment_3.reader.VIPReader; // 引入reader包中的VIPReader类
import cn.vscoder.experiment_3.common.PayException; // 引入common包中的PayException异常类
import java.util.*; // 导入常用集合类如LinkedList和ArrayList
public class RentBookManagenew { // 类定义使用public修饰
/* 1. 定义所需的成员变量 */
static final int deadTime = 10; // 静态常量规定租期上限天数final修饰不可修改
double normalRent = 0.1; // 实例变量正常租金费率
double delayRent = 0.4; // 实例变量逾期租金费率
VIPReader renter; // 当前还书的会员读者对象
RentRecord rentrecord; // 当前操作的租赁记录对象
public LinkedList<RentBook> booklist; // 图书列表保存所有可租图书
public ArrayList<VIPReader> readerlist; // 读者列表保存所有会员读者
public ArrayList<RentRecord> rentlist; // 租借记录列表
public ArrayList<String> returnlist; // 还书记录信息列表
int j; // 循环索引变量
/* 2. 无参构造函数 */
public RentBookManagenew() {
booklist = new LinkedList<>();
readerlist = new ArrayList<>();
rentlist = new ArrayList<>();
returnlist = new ArrayList<>();
}
/* 3. 相关getter/setter方法 */
public static double getDeadTime() {
return deadTime;
}
public void setNormalRent(double newNR) {
normalRent = newNR;
}
public double getNormalRent() {
return normalRent;
}
public void setDelayRent(double newNR) {
delayRent = newNR;
}
public double getDelayRent() {
return delayRent;
}
/* 4. 图书信息操作相关方法 */
public void addBook(String isbn, String bname, String bauthor, String bpublisher, double bprice, String no) {
booklist.add(new RentBook(isbn, bname, bauthor, bpublisher, bprice, no));
}
public void addBook(int i, String isbn, String bname, String bauthor, String bpublisher, double bprice, String no) {
booklist.add(i, new RentBook(isbn, bname, bauthor, bpublisher, bprice, no));
}
public void searchBook(String bookNo) {
boolean flag = false;
for (j = 0; j < booklist.size(); j++) {
if (booklist.get(j).getBookNo().equals(bookNo)) {
System.out.println(booklist.get(j));
flag = true;
}
}
if (!flag)
System.out.println("未找到指定图书。");
}
public void editBook(String isbn, double bprice) {
for (j = 0; j < booklist.size(); j++) {
if (booklist.get(j).getISBN().equals(isbn)) {
booklist.get(j).setPrice(bprice);
System.out.println(booklist.get(j));
}
}
}
public void deleteBook(String isbn) {
for (j = 0; j < booklist.size(); j++) {
if (booklist.get(j).getISBN().equals(isbn)) {
booklist.remove(j);
System.out.println("成功删除图书。");
}
}
}
public void displayBook() {
for (RentBook b : booklist)
System.out.println(b);
}
/* 5. 读者信息添加与展示 */
public void addReader(String name, String grade) {
readerlist.add(new VIPReader(name, grade));
}
public void displayReader() {
for (VIPReader r : readerlist)
System.out.println(r);
}
/* 6. 与租赁业务相关的方法 */
public void addRentRecord(RentBook bk, VIPReader rd, String rdate) {
if (rentlist.size() == 0) {
rentlist.add(new RentRecord(bk, rd, rdate));
} else {
boolean flag = true;
for (j = 0; j < rentlist.size(); j++) {
if (rentlist.get(j).getBookNo().equals(bk.getBookNo())) {
System.out.println(rentlist.get(j).getBookNo() + " 已被租借");
flag = false;
}
}
if (flag) {
rentlist.add(new RentRecord(bk, rd, rdate));
}
}
}
public void returnBook(RentBook bk, VIPReader rd, String redate) {
for (j = 0; j < rentlist.size(); j++) {
if (rentlist.get(j).getBookNo().equals(bk.getBookNo())) {
renter = rd;
rentlist.get(j).setReturnDate(redate);
rentlist.get(j).setRent(deadTime, normalRent, delayRent, renter.getPercent());
rentlist.get(j).setBonusPoints();
renter.setBonusPoints(rentlist.get(j).getBonusPoints());
renter.promotion(renter.getReaderGrade());
if (renting()) {
returnlist.add("\n" + renter.getReaderName() + " | " + renter.getReaderGrade() + " 会员账户余额=" + renter.getBalance()
+ " 当前积分=" + renter.getBonusPoints() + "\n借阅图书信息: " + rentlist.get(j).toString());
rentlist.remove(j);
}
}
}
}
public boolean renting() {
try {
renter.payRent(rentlist.get(j).getRent());
System.out.println(renter.getReaderName() + " 支付租金:" + rentlist.get(j).getRent() + " 成功!");
return true;
} catch (PayException pe) {
System.out.println(renter.getReaderName() + pe);
return false;
}
}
public void displayRentInfo() {
for (RentRecord br : rentlist)
System.out.println(br);
}
public void displayReturnInfo() {
for (String bre : returnlist)
System.out.println(bre);
}
}

View File

@ -0,0 +1,118 @@
package cn.vscoder.experiment_3.rent;
/*例3-5 用来处理图书租阅记录的实体类设计了6个属性、2个构造方法、9个成员方法、1个内部类 */
import java.util.*; //加载工具类包的类时间计算需要用到CalendarDate
import cn.vscoder.experiment_3.book.RentBook;
import cn.vscoder.experiment_3.reader.VIPReader;
import cn.vscoder.experiment_3.common.DecF; //自定义通用类对double型值只保留2位小数
public class RentRecord // 租书记录类
{
private String bookNo; //被租图书入库编号
private int readerID; //读者编号
private String rentDate=""; //租书日期格式20201015
private String returnDate=""; //还书日期
private double rents; //租金
private int bonusPoints; //积分
public RentRecord(RentBook rb, VIPReader reader, String rentd)
{
this.bookNo = rb.getBookNo();
this.readerID = reader.getReaderID();
rentDate = rentd;
returnDate = "";
rents = 0;
bonusPoints = 0;
}
public RentRecord(RentBook rb, VIPReader reader, String rentd, String returnd) //添加public修饰符
{
this(rb, reader, rentd);
returnDate = returnd;
bonusPoints = getBonusPoints();
}
public int getReaderID() //获取读者编号
{
return readerID;
}
public String getBookNo() //获取入库号
{
return bookNo;
}
public void setRentDate(String rentdate) //设置租书日期
{
this.rentDate = rentdate;
}
public void setReturnDate(String returndate) //设置还书日期
{
this.returnDate = returndate;
}
public long sumRentdays() //计算租阅总天数的成员方法
{
SumDays sd = new SumDays(); //创建内部类的对象
return sd.setRentDays(rentDate, returnDate); //调用内部类的方法计算租阅总天数
}
public void setRent(int deadTime, double nRent, double dRent, double pencent) //计算租金
{
int rentDays = (int)sumRentdays();
if(rentDays <= deadTime)
rents = DecF.DecD(rentDays * nRent * pencent); //在规定期限内按正常租阅费率计算租金
else
rents = DecF.DecD(((rentDays - deadTime) * dRent + deadTime * nRent) * pencent); //超期租金
}
public double getRent() //获取租金
{
return rents;
}
public void setBonusPoints() //计算积分
{
bonusPoints = bonusPoints + (int)sumRentdays(); //按照租阅天数累积会员积分每天1分
}
public int getBonusPoints() //获取积分
{
return bonusPoints;
}
public String toString() //重写toString()方法
{
if(returnDate.length() == 0) //借书时
return " 入库号:" + getBookNo() + " 租借者:" + getReaderID() + " 租书日期:" + rentDate;
else //还书时
return " 入库号:" + getBookNo() + " 租借者:" + getReaderID() + " 租书日期:" + rentDate +
" 还书日期:" + returnDate + " 租阅天数:" + sumRentdays() + " 积分:" + getBonusPoints() +
" 租金:" + getRent();
}
/* 计算租阅总天数的内部类 */
private class SumDays
{
Calendar c = Calendar.getInstance();
public long setRentDays(String rentD, String sendD) //根据租书日期和还书日期计算租阅总天数
{
int y1 = Integer.parseInt(rentD.substring(0, 4)); //提取租书日期的年份
int m1 = Integer.parseInt(rentD.substring(4, 6)); //提取租书日期的月份
int d1 = Integer.parseInt(rentD.substring(6, 8)); //提取租书日期的日子
c.set(y1, m1, d1); //转化为日期型
long getDate = c.getTimeInMillis(); //租书时间转化为毫秒数
int y2 = Integer.parseInt(sendD.substring(0, 4)); //提取还书日期的年份
int m2 = Integer.parseInt(sendD.substring(4, 6)); //提取还书日期的月份
int d2 = Integer.parseInt(sendD.substring(6, 8)); //提取还书日期的日子
c.set(y2, m2, d2);
long sendDate = c.getTimeInMillis(); //还书时间转化为毫秒数
long rentDays = (sendDate - getDate) / (1000 * 60 * 60 * 24); //计算租书和还书日期相差天数
return rentDays;
}
}
}

View File

@ -0,0 +1,27 @@
package cn.vscoder.experiment_3.test;
import cn.vscoder.experiment_3.book.Book;
import cn.vscoder.experiment_3.book.RentBook;
import cn.vscoder.experiment_3.reader.Reader;
import cn.vscoder.experiment_3.reader.VIPReader;
public class Test {
public static void main(String[] args) {
Book book=new Book("9787508353937","Head First设计模式","Eric Freeman / Elisabeth Freeman","中国电力出版社",128);
System.out.println(book.getBookName());
book.setPrice(book.getPrice()*0.8);
System.out.println(book);
Reader reader1=new Reader();
Reader reader2=new Reader();
System.out.println(reader1);
System.out.println(reader2);
RentBook rentBook=new RentBook("97875","设计模式","Eric Freeman","北京大学出版社",128,"in0001");
System.out.println(rentBook);
VIPReader vipreader1=new VIPReader("张三","VIP");
VIPReader vipreader2=new VIPReader("李四","普通会员");
VIPReader vipreader3=new VIPReader("王二","非会员");
System.out.println(vipreader1);
System.out.println(vipreader2);
System.out.println(vipreader3);
}
}

View File

@ -0,0 +1,38 @@
package cn.vscoder.experiment_3.test;
import cn.vscoder.experiment_3.book.RentBook;
import cn.vscoder.experiment_3.common.PayException;
import cn.vscoder.experiment_3.reader.VIPReader;
import cn.vscoder.experiment_3.rent.RentBookManage;
public class TestRentBookManage {
public static void main(String[] args) throws PayException {
System.out.println("欢迎进入图书租阅管理系统!");
RentBookManage bm = new RentBookManage();
bm.addBook(new RentBook("0001", "java", "王三", "南京大学出版社", 23.5, "in001"));
bm.addBook(new RentBook("0002", "eclipse", "王婆", "北京大学出版社", 53.5, "in002"));
bm.addBook(new RentBook("0003", "数据结构", "张斯", "清华大学出版社", 45.5, "in003"));
bm.addBook(1, new RentBook("0004", "数据分析", "鱼鱼", "忧伤出版社", 45.3, "in005"));
bm.displayAllBooks();
RentBook rentBook = bm.searchBook("java");
bm.editBook("java", 100);
bm.deleteBook("数据分析");
bm.displayAllBooks();
bm.addReader(new VIPReader("张三", "普通会员"));
bm.addReader("李四", "VIP");
bm.addReader("王二", "非会员");
bm.displayAllReaders();
if (bm.rentBook(bm.readerlist.get(0), bm.searchBook("eclipse"), 10)) {
bm.printRentlist();
} else {
bm.readerlist.get(0).setBalance(100);
}
bm.rentBook(bm.readerlist.get(0), bm.searchBook("eclipse"), 10);
bm.printRentlist();
}
}

View File

@ -0,0 +1,59 @@
package cn.vscoder.experiment_3.test;
/* 测试功能:测试图书和读者的添加功能,并调用相关方法测试借书与还书功能 */
import cn.vscoder.experiment_3.rent.*; // 导入 rent 包中的所有类
public class TestRentBookManageNew {
public static void main(String args[]) {
System.out.println("RentBookManagenew 测试程序开始:");
RentBookManagenew bm = new RentBookManagenew();
/* 测试图书的添加和显示 */
bm.addBook("978-7-305-13888-3", "Java 课程设计指导", "施伯乐", "南京大学出版社", 31, "IT-202-01");
bm.addBook("978-7-103-01234-2", "数据结构", "严蔚敏", "清华大学出版社", 41.2, "IT-401-01");
bm.addBook("978-7-113-07777-1", "VB学习与考研指导", "施伯乐", "中国铁道出版社", 35, "IT-301-01");
bm.displayBook(); // 显示所有图书信息
System.out.println("\n调用 editBook(“978-7-113-07777-1”, 28.5)");
bm.editBook("978-7-113-07777-1", 28.5); // 修改图书价格
/* 测试读者的添加和设置余额 */
System.out.println("\n调用 addReader() 和 setBalance(1000 / 500 / 80)");
bm.addReader("张三", "普通会员");
bm.addReader("李四", "非会员");
bm.addReader("王小强", "VIP");
bm.readerlist.get(0).setBalance(1000); // 第1位读者余额为1000
bm.readerlist.get(1).setBalance(500); // 第2位读者余额为500
bm.readerlist.get(2).setBalance(80); // 第3位读者余额为80
bm.displayReader(); // 显示所有读者信息
/* 测试图书租借功能 */
System.out.println("\n测试图书租借与归还功能");
// 1号读者借了图书1租借日期2017年7月7日
bm.addRentRecord(bm.booklist.get(0), bm.readerlist.get(0), "20170707");
// 2号读者借了图书2租借日期2019年9月9日
bm.addRentRecord(bm.booklist.get(1), bm.readerlist.get(1), "20190909");
// 2号读者归还图书2归还日期2020年2月18日
bm.returnBook(bm.booklist.get(1), bm.readerlist.get(1), "20200218");
// 3号读者借了图书2租借日期2020年3月1日
bm.addRentRecord(bm.booklist.get(1), bm.readerlist.get(2), "20200301");
// 2号读者试图归还图书3未借出归还日期2020年6月16日测试失败情况
bm.returnBook(bm.booklist.get(2), bm.readerlist.get(1), "20200616");
// 1号读者归还图书1归还日期2020年10月1日
bm.returnBook(bm.booklist.get(0), bm.readerlist.get(0), "20201001");
System.out.println("\n显示所有归还记录");
bm.displayReturnInfo(); // 显示所有归还记录
System.out.println("\n显示当前借阅清单");
bm.displayRentInfo(); // 显示当前仍在借阅的图书记录
}
}