import java.io.Serializable; import java.text.Collator; import java.util.Locale; public class Book implements Serializable,Comparable2、BorrowBook类{ private int number;//数量 private double price;//价格 private String bookId;//书号 private String bookName;//书名 private String writer;//作者 private String publishingHouse;//出版社 private String publicationDate;//出版日期 public String getBookId() { return bookId; } public void setBookId(String bookId) { this.bookId = bookId; } public String getBookName() { return bookName; } public void setBookName(String bookName) { this.bookName = bookName; } public String getWriter() { return writer; } public void setWriter(String writer) { this.writer = writer; } public String getPublishingHouse() { return publishingHouse; } public void setPublishingHouse(String publishingHouse) { this.publishingHouse = publishingHouse; } public String getPublicationDate() { return publicationDate; } public void setPublicationDate(String publicationDate) { this.publicationDate = publicationDate; } public int getNumber() { return number; } public void setNumber(int number) { this.number = number; } public double getPrice() { return price; } public void setPrice(double price) { this.price = price; } public Book() { } public Book(String bookId, String bookName, String writer, String publishingHouse, String publicationDate, int number, double price) { this.bookId = bookId; this.bookName = bookName; this.writer = writer; this.publishingHouse = publishingHouse; this.publicationDate = publicationDate; this.number = number; this.price = price; } @Override public String toString() { return "Book【" + "bookId:'" + bookId + ''' + ", bookName:'" + bookName + ''' + ", writer:'" + writer + ''' + ", publishingHouse:'" + publishingHouse + ''' + ", publicationDate:'" + publicationDate + ''' + ", number:" + number + ", price:" + price + '】'; } @Override public int compareTo(Book o) { Collator.getInstance(Locale.CHINA); int i = bookName.compareTo(o.bookName); if (i == 0){ for (int i1 = 0; i1 < bookId.length(); i1++) { if (bookId.charAt(i1) != o.bookId.charAt(i1)){ return bookId.charAt(i1) - o.bookId.charAt(i1); } } return 0; }else { return i; } } }
import java.io.Serializable;
public class BorrowBook implements Serializable {
private String studentId;//学号
private String studentName;//学生姓名
private String bookId;//书号
private String bookName;//书名
private String borrowDate;//借书时间
private String shouldReturnDate;//应还时间
private String returnDate;//实际还书时间
public String getStudentId() {
return studentId;
}
public void setStudentId(String studentId) {
this.studentId = studentId;
}
public String getStudentName() {
return studentName;
}
public void setStudentName(String studentName) {
this.studentName = studentName;
}
public String getBookId() {
return bookId;
}
public void setBookId(String bookId) {
this.bookId = bookId;
}
public String getBookName() {
return bookName;
}
public void setBookName(String bookName) {
this.bookName = bookName;
}
public String getBorrowDate() {
return borrowDate;
}
public void setBorrowDate(String borrowDate) {
this.borrowDate = borrowDate;
}
public String getShouldReturnDate() {
return shouldReturnDate;
}
public void setShouldReturnDate(String shouldReturnDate) {
this.shouldReturnDate = shouldReturnDate;
}
public String getReturnDate() {
return returnDate;
}
public void setReturnDate(String returnDate) {
this.returnDate = returnDate;
}
public BorrowBook() {
}
public BorrowBook(String studentId, String studentName, String bookId, String bookName, String borrowDate, String shouldReturnDate, String returnDate) {
this.studentId = studentId;
this.studentName = studentName;
this.bookId = bookId;
this.bookName = bookName;
this.borrowDate = borrowDate;
this.shouldReturnDate = shouldReturnDate;
this.returnDate = returnDate;
}
@Override
public String toString() {
return "BorrowBook【" +
"studentId:'" + studentId + ''' +
", studentName:'" + studentName + ''' +
", bookId:'" + bookId + ''' +
", bookName:'" + bookName + ''' +
", borrowDate:'" + borrowDate + ''' +
", shouldReturnDate:'" + shouldReturnDate + ''' +
", returnDate:'" + returnDate + ''' +
'】';
}
}
3、Reader类
import java.io.Serializable; import java.text.Collator; import java.util.Locale; public class Reader implements Serializable,Comparable4、User类{ private String studentId;//学号 private String studentName;//姓名 private String college;//学院 private String specialty;//专业 private String gradeAndClass;//班级 public String getStudentId() { return studentId; } public void setStudentId(String studentId) { this.studentId = studentId; } public String getStudentName() { return studentName; } public void setStudentName(String studentName) { this.studentName = studentName; } public String getCollege() { return college; } public void setCollege(String college) { this.college = college; } public String getSpecialty() { return specialty; } public void setSpecialty(String specialty) { this.specialty = specialty; } public String getGradeAndClass() { return gradeAndClass; } public void setGradeAndClass(String gradeAndClass) { this.gradeAndClass = gradeAndClass; } public Reader() { } public Reader(String studentId, String studentName, String college, String specialty, String gradeAndClass) { this.studentId = studentId; this.studentName = studentName; this.college = college; this.specialty = specialty; this.gradeAndClass = gradeAndClass; } @Override public String toString() { return "Reader【" + "studentId:'" + studentId + ''' + ", studentName:'" + studentName + ''' + ", college:'" + college + ''' + ", specialty:'" + specialty + ''' + ", gradeAndClass:'" + gradeAndClass + ''' + '】'; } @Override public int compareTo(Reader o) { Collator.getInstance(Locale.CHINA); //Comparator
import java.io.Serializable;
public class User implements Serializable {
private String userId;//账号
private String userName;//用户名
private String passWord;//密码
public String getUserId() {
return userId;
}
public void setUserId(String userId) {
this.userId = userId;
}
public String getUserName() {
return userName;
}
public void setUserName(String userName) {
this.userName = userName;
}
public String getPassWord() {
return passWord;
}
public void setPassWord(String passWord) {
this.passWord = passWord;
}
public User() {
}
public User(String userId, String userName, String passWord) {
this.userId = userId;
this.userName = userName;
this.passWord = passWord;
}
@Override
public String toString() {
return "userName【" +
"userId:'" + userId + ''' +
", userName:'" + userName + ''' +
", passWord:'" + passWord + ''' +
'】';
}
}
5、IO类
将需要用到的io流操作都封装在这个类里面方便调用
import java.io.*;
import java.util.ArrayList;
import java.util.List;
public class IO {
public IO() {
}
private static void store(List list, FileOutputStream fos) throws IOException {
ObjectOutputStream oos = new ObjectOutputStream(fos);//ObjectOutputStream将字符流转换为字节流
oos.writeObject(list);
oos.close();
}
private static List load(FileInputStream fis, File file){
List list = new ArrayList<>();
if (file.length()==0){
try {
fis.close();
} catch (IOException e) {
throw new RuntimeException(e);
}
}else {
ObjectInputStream ois = null;//ObjectInputStream将字节流转换为字符流
try {
ois = new ObjectInputStream(fis);
} catch (IOException e) {
throw new RuntimeException(e);
}
try {
list = (List) ois.readObject();
ois.close();
} catch (IOException e) {
throw new RuntimeException(e);
} catch (ClassNotFoundException e) {
throw new RuntimeException(e);
}
}
return list;
}
public void shoreBook(List list) throws IOException {
FileOutputStream fos = new FileOutputStream(new File("src/Data//books.txt"));
store(list,fos);
}
public List loadBook() throws IOException, ClassNotFoundException {
File file = new File("src/Data//books.txt");
if (!file.exists()){
file.createNewFile();
}
FileInputStream fis = null;
try {
fis = new FileInputStream(file);
} catch (FileNotFoundException e) {
throw new RuntimeException(e);
}
return (List)load(fis,file);
}
public void storeReader(List list) throws IOException {
File file = new File("src/Data//readers.txt");
FileOutputStream fos = null;
try {
fos = new FileOutputStream(file);
if (!file.exists()){
file.createNewFile();
}
} catch (IOException e) {
throw new RuntimeException(e);
}
store(list,fos);
}
public List loadReader() throws IOException, ClassNotFoundException {
File file = new File("src/Data//readers.txt");
if (!file.exists()){
file.createNewFile();
}
FileInputStream fis = new FileInputStream(file);
return (ArrayList)load(fis,file);
}
public void storeBorrowBook(List list) throws IOException {
FileOutputStream fos = new FileOutputStream("src/Data//borrowBooks.txt");
store(list,fos);
}
public List loadBorrowBook() throws IOException, ClassNotFoundException {
File file = new File("src/Data//borrowBooks.txt");
if (!file.exists()){
file.createNewFile();
}
FileInputStream fis = new FileInputStream(file);
return (ArrayList)load(fis,file);
}
public void storeUser(List list) throws IOException {
FileOutputStream fos = new FileOutputStream("src/Data//users.txt");
store(list,fos);
}
public List loaduser() throws IOException {
File file = new File("src/Data//users.txt");
if (!file.exists()){
file.createNewFile();
}
FileInputStream fis = new FileInputStream(file);
return (ArrayList)load(fis,file);
}
}
6、Main类
实现了主要的功能,代码放在最后
二、首页功能 1、用户注册①让用户输入用户名
②系统生成一个唯一的不重复的8位数账号
③让用户设置密码,连续两次输入一致设置成功
④将生成的用户信息录入系统
生成8位数账号代码:
private static String getRandomCardId(Listusers) { Random r = new Random(); while (true){ //生成8位数字 StringBuilder userId =new StringBuilder(); for (int i = 0; i < 8; i++) { userId.append(r.nextInt(10)); } //判断是否与其他用户重复,根据userId查询用户对象 User user = getUserByUserId(userId.toString(),users); if(user == null){ //userId没有重复,可以做新账户的账号 return userId.toString(); } } }
主要代码:
private static void register(List2、用户登录users, Scanner sc, IO io) throws IOException { User user = new User(); System.out.println("请输入用户名:"); String userName = sc.next(); user.setUserName(userName); while(true) { System.out.println("请输入账户密码:"); String passWorld = sc.next(); System.out.println("请您输入确认密码:"); String okPassWorld = sc.next(); if (okPassWorld.equals(passWorld)) { //密码认证通过,可以注入给用户对象 user.setPassWord(okPassWorld); break;//密码录入成功,退出死循环 }else{ System.out.println("对不起,您输入的2次密码不一致,请重新确认~~~"); } } String userId = getRandomCardId(users); user.setUserId(userId); users.add(user); io.storeUser(users); System.out.println("恭喜您," + userName + "先生/女士,您注册成功,您的卡号是:" + userId + "请妥善保管卡号"); }
代码:
//判断是否存在user
if (users.size() == 0){
System.out.println("请先注册后登录~~~");
return;
}
while (true){
//user存在,正式开始登陆
System.out.println("请你输入登陆userId:");
String cardId = sc.next();
//判断userId是否存在(根据userId去账户集合中查询账户对象)
User user =getUserByUserId(cardId,users);
if (user != null){
while (true){
//userId存在
//让用户输入密码,认证密码
System.out.println("请输入登陆密码:");
String passWord = sc.next();
//判断当前用户对象的密码是否与输入的密码一致
if (user.getPassWord().equals(passWord)){
//登陆成功了
System.out.println("恭喜您," + user.getUserName() + "先生|女士进入系统~~~");
//展示登录后的操作页
showUserCommand(sc,io);
return;//退出登陆方法
}else{
System.out.println("对不起,您输入的密码有误~~~");
}
}
}else {
System.out.println("对不起,系统中不存在该用户账号~~~");
}
}
3、用户信息管理
包含3个功能,删除、查找、显示,每个功能都封装成函数
①用户信息删除
private static void deleteUser(Scanner sc, IO io, Listusers) throws IOException { System.out.println("请输入要删除用户的账号:"); String userId = sc.next(); User user = getUserByUserId(userId,users); if (user != null){ System.out.println("请输入此用户的密码:"); String passWord = sc.next(); if (user.getPassWord().equals(passWord)){ int index = returnIndexByUserId(userId,users); users.remove(index); io.storeUser(users); System.out.println("删除成功~~~"); } }else { System.out.println("系统中不存在此用户账号~~~"); } }
②用户信息查找
private static void findUser(Scanner sc, Listusers) { System.out.println("请输入用户名:"); String userName = sc.next(); for (User user:users) { if (user.getUserName().equals(userName)){ System.out.println(user.getUserName() + "的账号为:" + user.getUserId()); return; } } System.out.println("系统中不存在此用户名~~~"); }
③用户信息列表显示
private static void printUser(Listusers) { if (users.size() == 0){ System.out.println("系统中还没有用户信息~~~"); return; } for (User user:users) { System.out.println(user.getUserName() + "的账号为:" + user.getUserId()); } }
主要代码:
private static void manageUserInformation(Scanner sc, IO io, List三、登录成功后功能users) throws IOException { while (true){ System.out.println("================1、用户信息删除==================="); System.out.println("================2、用户信息查找==================="); System.out.println("================3、用户信息列表显示================"); System.out.println("================0、退出用户信息管理================"); System.out.println("请选择操作:"); int select = sc.nextInt(); switch (select){ case 1: deleteUser(sc,io,users);//删除 break; case 2: findUser(sc,users);//查找 break; case 3: printUser(users);//输出全部用户信息,不包括密码 break; case 0: return;//退出用户信息管理 } } }
将每一个功能封装成方法,这里只展示一下结构,具体的代码放在最后
1、读者信息管理
private static void readersInformationManage(Scanner sc,List readers,IO io) throws IOException {
while(true){
System.out.println("================1、读者信息的添加================");
System.out.println("================2、读者信息的查询================");
System.out.println("================3、修改读者的信息================");
System.out.println("================4、删除读者的信息================");
System.out.println("================5、读者信息的排序================");
System.out.println("================6、读者信息的显示================");
System.out.println("================0、退出此界面=====================");
System.out.println("请选择操作:");
int select = sc.nextInt();
switch (select){
case 1:
addReader(sc,readers,io);//读者信息的添加
break;
case 2:
findReader(sc,readers);//读者信息的查询
break;
case 3:
modifyReader(sc,readers,io);//修改读者的信息
break;
case 4:
deleteReader(sc,readers,io);//删除读者的信息
break;
case 5:
sortReader(readers,io);//读者信息的排序
break;
case 6:
printReader(readers);//读者信息的显示
break;
case 0://退出此界面
return;
}
}
}
2、图书信息管理
private static void booksInformationManage(Scanner sc, List books, IO io) throws IOException {
while(true){
System.out.println("================1、图书信息的添加================");
System.out.println("================2、图书信息的查询================");
System.out.println("================3、图书信息的修改================");
System.out.println("================4、图书信息的删除================");
System.out.println("================5、图书信息的排序================");
System.out.println("================6、图书信息的显示================");
System.out.println("================0、退出功能=====================");
int select = sc.nextInt();
switch(select){
case 1:
addBook(sc,books,io);
break;
case 2:
findBook(sc,books);
break;
case 3:
modifyBook(sc,books,io);
break;
case 4:
deleteBook(sc,books,io);
break;
case 5:
sortBook(books,io);
break;
case 6:
printBook(books);
break;
case 0:
return;
}
}
}
3、图书借阅
①用户输入学号,书号
②学号数号均存在,且书的数量不为0,可以进行借阅操作
③使用时间日期相关类,记录接书时间
④修改图书表中和图书借阅表中的信息
4、图书归还①输入学号书号,在图书借阅表中查询是否存在相关对借阅信息
②如存在,进行还书操作
③使用时间日期相关类,记录还书时间
④修改图书表中和图书借阅表中的信息
5、图书借阅查询
private static void findBorrowBook(Scanner sc, List borrowBooks, List readers,List books) {
while(true){
System.out.println("================1、按学号进行查询================");
System.out.println("================2、按书号进行查询================");
System.out.println("================3、按学院进行查询================");
System.out.println("================4、显示全部借阅信息===============");
System.out.println("================0、退出功能======================");
System.out.println("请选择操作:");
int select = sc.nextInt();
switch (select){
case 1:
findBorrowByStudentId(sc,borrowBooks,readers);
break;
case 2:
findBorrowBookByBookId(sc,borrowBooks,books);
break;
case 3:
findBorrowBookByCollege(sc,borrowBooks,readers);
case 4:
printBorrowBook(borrowBooks);
break;
case 0:
return;
}
}
}
四、实现功能的主要方法的代码
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.*;
public class Main {
public static void main(String[] args) throws IOException, ClassNotFoundException {
Scanner sc = new Scanner(System.in);
IO io = new IO();
List users;//用户
users = io.loaduser();//从文件中导出用户
while(true) {
System.out.println("=======================图书管理系统======================");
System.out.println("1、登录");
System.out.println("2、注册");
System.out.println("3、管理users信息");
System.out.println("请选择操作:");
int command = sc.nextInt();
switch(command){
case 1:
login(users,sc,io);//登录
break;
case 2:
register(users,sc,io);//注册
break;
case 3:
manageUserInformation(sc,io,users);//用户信息管理
}
}
}
private static void manageUserInformation(Scanner sc, IO io, List users) throws IOException {
while (true){
System.out.println("================1、用户信息删除===================");
System.out.println("================2、用户信息查找===================");
System.out.println("================3、用户信息列表显示================");
System.out.println("================0、退出用户信息管理================");
System.out.println("请选择操作:");
int select = sc.nextInt();
switch (select){
case 1:
deleteUser(sc,io,users);//删除
break;
case 2:
findUser(sc,users);//查找
break;
case 3:
printUser(users);//输出全部用户信息,不包括密码
break;
case 0:
return;//退出用户信息管理
}
}
}
private static void printUser(List users) {
if (users.size() == 0){
System.out.println("系统中还没有用户信息~~~");
return;
}
for (User user:users) {
System.out.println(user.getUserName() + "的账号为:" + user.getUserId());
}
}
private static void findUser(Scanner sc, List users) {
System.out.println("请输入用户名:");
String userName = sc.next();
for (User user:users) {
if (user.getUserName().equals(userName)){
System.out.println(user.getUserName() + "的账号为:" + user.getUserId());
return;
}
}
System.out.println("系统中不存在此用户名~~~");
}
private static void deleteUser(Scanner sc, IO io, List users) throws IOException {
System.out.println("请输入要删除用户的账号:");
String userId = sc.next();
User user = getUserByUserId(userId,users);
if (user != null){
System.out.println("请输入此用户的密码:");
String passWord = sc.next();
if (user.getPassWord().equals(passWord)){
int index = returnIndexByUserId(userId,users);
users.remove(index);
io.storeUser(users);
System.out.println("删除成功~~~");
}
}else {
System.out.println("系统中不存在此用户账号~~~");
}
}
private static int returnIndexByUserId(String userId, List users) {
for (int i = 0; i < users.size(); i++) {
User user = users.get(i);
if (user.getUserId().equals(userId)){
return i;
}
}
return -1;
}
private static void register(List users, Scanner sc, IO io) throws IOException {
User user = new User();
System.out.println("请输入用户名:");
String userName = sc.next();
user.setUserName(userName);
while(true) {
System.out.println("请输入账户密码:");
String passWorld = sc.next();
System.out.println("请您输入确认密码:");
String okPassWorld = sc.next();
if (okPassWorld.equals(passWorld)) {
//密码认证通过,可以注入给用户对象
user.setPassWord(okPassWorld);
break;//密码录入成功,退出死循环
}else{
System.out.println("对不起,您输入的2次密码不一致,请重新确认~~~");
}
}
String userId = getRandomCardId(users);
user.setUserId(userId);
users.add(user);
io.storeUser(users);
System.out.println("恭喜您," + userName + "先生/女士,您注册成功,您的卡号是:" + userId + "请妥善保管卡号");
}
private static String getRandomCardId(List users) {
Random r = new Random();
while (true){
//生成8位数字
StringBuilder userId =new StringBuilder();
for (int i = 0; i < 8; i++) {
userId.append(r.nextInt(10));
}
//判断是否与其他用户重复,根据userId查询用户对象
User user = getUserByUserId(userId.toString(),users);
if(user == null){
//userId没有重复,可以做新账户的账号
return userId.toString();
}
}
}
private static User getUserByUserId(String userId, List users) {
for (User user:users) {
if (user.getUserId().equals(userId)){
return user;
}
}
return null;
}
private static void login(List users, Scanner sc, IO io) throws IOException, ClassNotFoundException {
//判断是否存在user
if (users.size() == 0){
System.out.println("请先注册后登录~~~");
return;
}
while (true){
//user存在,正式开始登陆
System.out.println("请你输入登陆userId:");
String cardId = sc.next();
//判断userId是否存在(根据userId去账户集合中查询账户对象)
User user =getUserByUserId(cardId,users);
if (user != null){
while (true){
//userId存在
//让用户输入密码,认证密码
System.out.println("请输入登陆密码:");
String passWord = sc.next();
//判断当前用户对象的密码是否与输入的密码一致
if (user.getPassWord().equals(passWord)){
//登陆成功了
System.out.println("恭喜您," + user.getUserName() + "先生|女士进入系统~~~");
//展示登录后的操作页
showUserCommand(sc,io);
return;//退出登陆方法
}else{
System.out.println("对不起,您输入的密码有误~~~");
}
}
}else {
System.out.println("对不起,系统中不存在该用户账号~~~");
}
}
}
private static void showUserCommand(Scanner sc, IO io) throws IOException, ClassNotFoundException {
List books;
List readers;
List borrowBooks;
//从文件中读取已有信息
books = io.loadBook();
readers = io.loadReader();
borrowBooks = io.loadBorrowBook();
while(true){
System.out.println("==============欢迎使用图书管理系统==============");
System.out.println("================1、读者信息管理================");
System.out.println("================2、图书信息管理================");
System.out.println("================3、图书借阅====================");
System.out.println("================4、图书归还====================");
System.out.println("================5、图书借阅查询=================");
System.out.println("================0、退出系统====================");
System.out.println("请选择操作:");
int select = sc.nextInt();
switch (select){
case 1:
readersInformationManage(sc,readers,io);//读者信息管理
break;
case 2:
booksInformationManage(sc,books,io);//图书信息管理
break;
case 3:
borrowBook(sc,borrowBooks,io,books,readers);//图书借阅
break;
case 4:
returnBook(sc,borrowBooks,io,books,readers);//图书归还
break;
case 5:
findBorrowBook(sc,borrowBooks,readers,books);//图书借阅信息查询
break;
case 0:
return;//退出系统
}
}
}
private static void findBorrowBook(Scanner sc, List borrowBooks, List readers,List books) {
while(true){
System.out.println("================1、按学号进行查询================");
System.out.println("================2、按书号进行查询================");
System.out.println("================3、按学院进行查询================");
System.out.println("================4、显示全部借阅信息===============");
System.out.println("================0、退出功能======================");
System.out.println("请选择操作:");
int select = sc.nextInt();
switch (select){
case 1:
findBorrowByStudentId(sc,borrowBooks,readers);
break;
case 2:
findBorrowBookByBookId(sc,borrowBooks,books);
break;
case 3:
findBorrowBookByCollege(sc,borrowBooks,readers);
case 4:
printBorrowBook(borrowBooks);
break;
case 0:
return;
}
}
}
private static void printBorrowBook(List borrowBooks) {
if (borrowBooks.size() == 0){
System.out.println("系统中还没有借阅信息~~~");
}
borrowBooks.forEach(System.out::println);
}
private static void findBorrowBookByCollege(Scanner sc, List borrowBooks, List readers) {
//获取目标学院的读者信息
List readersList = findReaderByCollege(sc,readers);
//判断系统中是否有录入该学院的读者
if (readersList.size() != 0){
//有
String flag = "n";
List borrowBookList;
//遍历获取到的读者信息
for (Reader reader:readersList) {
borrowBookList = getBorrowBooksByStudentId(reader.getStudentId(),borrowBooks);//根据读者信息在图书借阅表中获取相关借阅信息
if (borrowBookList.size() != 0){//判断该读者是否在此借阅过图书
flag = "y";
borrowBookList.forEach(System.out::println);//有则输出
}
}
if (flag.equals("n")){
System.out.println("没有书被该学院的人借阅~~~");
}
}else {
System.out.println("抱歉,系统没有录入该学院的人~~~");
}
}
private static List findReaderByCollege(Scanner sc, List readers) {
List readerList = new ArrayList<>();
System.out.println("请输入学院:");
String college = sc.next();
for (Reader reader :readers) {
if (reader.getCollege().equals(college)){
readerList.add(reader);
}
}
return readerList;
}
private static void findBorrowBookByBookId(Scanner sc, List borrowBooks,List books) {
List borrowBookList;//用于记录查询到的借阅信息
Book book = getBookByBookId(sc, books);
//判断该书号对应图书是否存在
if (book != null){
//图书存在,从借阅信息表获取该图书相关借阅信息
borrowBookList = getBorrowBookByBookId(book.getBookId(),borrowBooks);
//判断图书借阅表中是否有相关借阅信息
if (borrowBookList.size() != 0){
//存在借阅信息,输出
borrowBookList.forEach(System.out::println);
System.out.println(borrowBookList);
}else {
System.out.println("此书没有被借阅~~~");
}
}
}
private static List getBorrowBookByBookId(String bookId, List borrowBooks) {
List borrowBookList = new ArrayList<>();
for (BorrowBook b:borrowBooks) {
if (b.getBookId().equals(bookId)){
borrowBookList.add(b);
}
}
return borrowBookList;
}
private static void findBorrowByStudentId(Scanner sc, List borrowBooks, List readers) {
List borrowBookList;// 用来存储该学生的借阅信息
System.out.println("请输入学号:");
String studentId = sc.next();
Reader reader = getReaderByStudentId(studentId,readers);
//判断读者是否存在
if (reader != null){
//存在,从图书借阅表中获取该读者相关借阅记录
borrowBookList = getBorrowBooksByStudentId(studentId,borrowBooks);
//判断图书借阅表中是否存在与此读者相关的记录
if (borrowBookList.size() != 0){
//存在,输出展示
borrowBookList.forEach(System.out::println);
}else {
//不存在
System.out.println("此用户没有借阅图书:");
}
}else {
//读者不存在
System.out.println("此用户不存在!!!");
}
}
private static void returnBook(Scanner sc, List borrowBooks, IO io, List books, List readers) throws IOException {
System.out.println("请输入学号:");
String studentId = sc.next();
Reader reader = getReaderByStudentId(studentId,readers);
if (reader != null){
List borrowBook = getBorrowBooksByStudentId(studentId,borrowBooks);
if (borrowBook.size() != 0){
while (true){
Book book = getBookByBookId(sc, books);
if (book != null){
for (BorrowBook b:borrowBook) {
if (b.getBookId().equals(book.getBookId())){
int index = returnIndexByBookIdAndStudentId(studentId,book.getBookId(),borrowBooks);
Date date = new Date();
long returnTime = date.getTime();
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy年MM月dd日 HH:mm:ss EEE");
String returnDate = simpleDateFormat.format(returnTime);
b.setReturnDate(returnDate);
borrowBooks.set(index,b);
book.setNumber(book.getNumber() + 1);
index = returnIndexByBookId(book.getBookId(),books);
books.set(index,book);
io.shoreBook(books);
io.storeBorrowBook(borrowBooks);
System.out.println("图书已成功归还~~~");
}
}
System.out.println("用户没有借阅此书~~~");
}else {
System.out.println("此书号不存在~~~");
}
System.out.println("是否继续还书?y/n");
while (true){
String select = sc.next();
if (select.equals("y")||select.equals("Y")){
break;
}else if (select.equals("n")||select.equals("N")){
return;
}else {
System.out.println("抱歉,您的输入系统不能识别,请重新输入~~~");
}
}
}
}else {
System.out.println("此用户没有借阅图书~~~");
}
}else {
System.out.println("此用户不存在,无法进行还书操作~~~");
}
}
private static int returnIndexByBookIdAndStudentId(String studentId, String bookId, List borrowBooks) {
for (int i = 0; i < borrowBooks.size(); i++) {
BorrowBook borrowBook = borrowBooks.get(i);
if (borrowBook.getBookId().equals(bookId) && borrowBook.getStudentId().equals(studentId)){
return i;
}
}
return -1;
}
private static List getBorrowBooksByStudentId(String studentId, List borrowBooks) {
List borrowBookList = new ArrayList<>();//用来存储查询到的该读者的借阅信息
for (BorrowBook borrowBook:borrowBooks) {
if (borrowBook.getStudentId().equals(studentId)){
borrowBookList.add(borrowBook);
}
}
return borrowBookList;
}
private static void borrowBook(Scanner sc, List borrowBooks, IO io,List books,List readers) throws IOException {
System.out.println("请输入学号:");
String studentId = sc.next();
Reader reader = getReaderByStudentId(studentId,readers);
//判断此学号对应读者是否存在
if (reader != null){
//存在
while (true){
Book book = getBookByBookId(sc,books);
//判断读者要借阅的书是否存在
if (book != null){
//存在,判断是否还有库存
if (book.getNumber() > 1){
//还有库存
BorrowBook borrowBook = new BorrowBook();
borrowBook.setStudentId(studentId);//在借阅信息表中录入学号
borrowBook.setStudentName(reader.getStudentName());//在借阅信息中录入读者姓名
borrowBook.setBookId(book.getBookId());//在借阅信息表中录入书号
borrowBook.setBookName(book.getBookName());//在借阅信息表中录入书名
Date date = new Date();
long borrowTime = date.getTime();//获取当前时间毫秒值
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy年MM月dd日 HH:mm:ss EEE");//格式化
String borrowDate = simpleDateFormat.format(borrowTime);
borrowBook.setBorrowDate(borrowDate);//将借书时间录入借阅信息表
long shouldReturnTime = borrowTime + 3*24*60*60*1000;
String shouldReturnDate = simpleDateFormat.format(shouldReturnTime);
borrowBook.setShouldReturnDate(shouldReturnDate);//设置三天后为应还时间
borrowBooks.add(borrowBook);
book.setNumber(book.getNumber() - 1);//对应书的数量-1
int index = returnIndexByBookId(book.getBookId(),books);
books.set(index,book);
io.shoreBook(books);//将图书信息存入文件
io.storeBorrowBook(borrowBooks);//将借阅信息存入文件
System.out.println("您的借书时间为:" + borrowDate);
System.out.println("请您在" + shouldReturnDate + "之前归还");
System.out.println("请问是否继续进行借阅操作?y/n");
while (true){
String select = sc.next();
if (select.equals("y")||select.equals("Y")){
System.out.println("请继续借阅操作~~~");
}else if (select.equals("n")||select.equals("N")){
return;
}else {
System.out.println("对不起,系统识别不出您的输入,请重新输入~~~");
}
}
}
}else {
System.out.println("此书不存在!!!");
System.out.println("请检测书号是否有误后重新输入~~~");
}
}
} else {
System.out.println("此用户不存在,无法进行借阅~~~");
}
}
private static void booksInformationManage(Scanner sc, List books, IO io) throws IOException {
while(true){
System.out.println("================1、图书信息的添加================");
System.out.println("================2、图书信息的查询================");
System.out.println("================3、图书信息的修改================");
System.out.println("================4、图书信息的删除================");
System.out.println("================5、图书信息的排序================");
System.out.println("================6、图书信息的显示================");
System.out.println("================0、退出功能=====================");
int select = sc.nextInt();
switch(select){
case 1:
addBook(sc,books,io);
break;
case 2:
findBook(sc,books);
break;
case 3:
modifyBook(sc,books,io);
break;
case 4:
deleteBook(sc,books,io);
break;
case 5:
sortBook(books,io);
break;
case 6:
printBook(books);
break;
case 0:
return;
}
}
}
private static void printBook(List books) {
if (books.size() == 0){
System.out.println("系统中还没有录入图书信息~~~");
return;
}
books.forEach(System.out::println);
}
private static void sortBook(List books, IO io) throws IOException {
Collections.sort(books);
io.shoreBook(books);
books.forEach(System.out::println);
}
private static void deleteBook(Scanner sc, List books, IO io) throws IOException {
while (true){
System.out.println("================1、按书号进行删除================");
System.out.println("================2、按书名进行删除================");
System.out.println("================0、退出删除功能==================");
System.out.println("请选操作:");
int select = sc.nextInt();
switch (select){
case 1:
deleteBookByBookId(sc,books,io);
break;
case 2:
deleteBookByBookName(sc,books,io);
break;
case 0:
return;
}
}
}
private static void deleteBookByBookName(Scanner sc, List books, IO io) throws IOException {
Book book = getBookByBookName(sc,books);
if (book != null){
int index = returnIndexByBookName(book.getBookName(), books);
books.remove(index);
io.shoreBook(books);
System.out.println("删除成功~~~");
}else {
System.out.println("此书不存在,不能进行删除操作!!!");
}
}
private static void deleteBookByBookId(Scanner sc, List books, IO io) throws IOException {
Book book = getBookByBookId(sc,books);
if (book != null){
int index = returnIndexByBookId(book.getBookId(),books);
books.remove(index);
io.shoreBook(books);
System.out.println("删除成功~~~");
}else {
System.out.println("此书不存在,不能进行删除操作!!!");
}
}
private static void modifyBook(Scanner sc, List books, IO io) throws IOException {
while (true){
System.out.println("===============1、按书号进行修改===============");
System.out.println("===============2、按书名进行修改===============");
System.out.println("===============0、退出修改功能=================");
System.out.println("请选择修改方式:");
int select = sc.nextInt();
switch (select){
case 1:
modifyBookByBookId(sc,books,io);
break;
case 2:
modifyBookBookByBookName(sc,books,io);
break;
case 0:
return;
}
}
}
private static void modifyBookBookByBookName(Scanner sc, List books, IO io) throws IOException {
Book book = getBookByBookName(sc,books);
if (book != null){
int index = returnIndexByBookName(book.getBookName(),books);
while(true){
System.out.println("===============1、修改书名===============");
System.out.println("===============2、修改书号===============");
System.out.println("===============3、修改作者===============");
System.out.println("===============4、修改出版社==============");
System.out.println("===============5、修改出版社日期===========");
System.out.println("===============6、修改库存数量============");
System.out.println("===============7、修改定价===============");
System.out.println("===============0、结束对此书的修改==========");
System.out.println("请选择要修改的内容:");
int select = sc.nextInt();
switch (select){
case 1:
System.out.println("请输入书名:");
String newBookName = sc.next();
book.setBookName(newBookName);
break;
case 2:
System.out.println("请输入书号:");
String newBookId = sc.next();
book.setBookId(newBookId);
break;
case 3:
System.out.println("请输入作者:");
String newWriter = sc.next();
book.setWriter(newWriter);
break;
case 4:
System.out.println("请输入出版社:");
String newPublishingHouse = sc.next();
book.setPublishingHouse(newPublishingHouse);
break;
case 5:
System.out.println("请输入出版日期:");
String newPublicationDate = sc.next();
book.setPublicationDate(newPublicationDate);
break;
case 6:
System.out.println("请输入库存数量:");
int newNumber = sc.nextInt();
book.setNumber(newNumber);
break;
case 7:
System.out.println("请输入定价:");
double newPrice = sc.nextDouble();
book.setPrice(newPrice);
break;
case 0:
books.set(index,book);
io.shoreBook(books);
return;
}
}
}
else {
System.out.println("此书不存在,不能进行修改操作!!!");
}
}
private static int returnIndexByBookName(String bookName, List books) {
for (int i = 0; i < books.size(); i++) {
Book book = books.get(i);
if (book.getBookName().equals(bookName)){
return i;
}
}
return -1;
}
private static Book getBookByBookName(Scanner sc, List books) {
System.out.println("请输入书名:");
String bookName = sc.next();
for (Book book: books) {
if (book.getBookName().equals(bookName)){
return book;
}
}
return null;
}
private static void modifyBookByBookId(Scanner sc, List books, IO io) throws IOException {
Book book = getBookByBookId(sc,books);
if (book != null){
int index = returnIndexByBookId(book.getBookId(),books);
while(true){
System.out.println("===============1、修改书名===============");
System.out.println("===============2、修改书号===============");
System.out.println("===============3、修改作者===============");
System.out.println("===============4、修改出版社==============");
System.out.println("===============5、修改出版社日期===========");
System.out.println("===============6、修改库存数量============");
System.out.println("===============7、修改定价===============");
System.out.println("===============0、结束对此书的修改==========");
System.out.println("请选择要修改的内容:");
int select = sc.nextInt();
switch (select){
case 1:
System.out.println("请输入书名:");
String newBookName = sc.next();
book.setBookName(newBookName);
System.out.println("书名修改成功~~~");
break;
case 2:
System.out.println("请输入书号:");
String newBookId = sc.next();
book.setBookId(newBookId);
System.out.println("书号修改成功~~~");
break;
case 3:
System.out.println("请输入作者:");
String newWriter = sc.next();
book.setWriter(newWriter);
System.out.println("作者修改成功~~~");
break;
case 4:
System.out.println("请输入出版社:");
String newPublishingHouse = sc.next();
book.setPublishingHouse(newPublishingHouse);
System.out.println("出版社修改成功~~~");
break;
case 5:
System.out.println("请输入出版日期:");
String newPublicationDate = sc.next();
book.setPublicationDate(newPublicationDate);
System.out.println("出版日期修改成功~~~");
break;
case 6:
System.out.println("请输入库存数量:");
int newNumber = sc.nextInt();
book.setNumber(newNumber);
System.out.println("库存数量修改成功~~~");
break;
case 7:
System.out.println("请输入定价:");
double newPrice = sc.nextDouble();
book.setPrice(newPrice);
System.out.println("定价修改成功~~~");
break;
case 0:
books.set(index,book);
io.shoreBook(books);
return;
}
}
}else {
System.out.println("此书不存在,不能进行修改操作!!!");
}
}
private static int returnIndexByBookId(String bookId, List books) {
for (int i = 0; i < books.size(); i++) {
Book book = books.get(i);
if (book.getBookId().equals(bookId)){
return i;
}
}
return -1;
}
private static void findBook(Scanner sc, List books) {
while (true){
System.out.println("===============1、根据书号查询===============");
System.out.println("===============2、根据作者查询===============");
System.out.println("===============3、根据出版社查询==============");
System.out.println("===============0、退出查询===================");
System.out.println("请选择查询方式:");
int select = sc.nextInt();
switch (select) {
case 1:
Book book = getBookByBookId(sc, books);
if (book != null) {
System.out.println(book);
} else {
System.out.println("查询不到此书号对应的书!!!");
}
break;
case 2:
List books1 = getBookByWriter(sc, books);
if (books1.size() == 0) {
System.out.println("查询不到此作者的作品!!!");
}else {
books1.forEach(System.out::println);
}
break;
case 3:
List books2 = getBookByPublishingHouse(sc,books);
if (books2.size() != 0){
books2.forEach(System.out::println);
}else {
System.out.println("查询不到此出版社出版的图书!!!");
}
break;
case 0:
return;
}
}
}
private static List getBookByPublishingHouse(Scanner sc, List books) {
System.out.println("请输入要查询的出版社:");
String publishingHouse = sc.next();
List books1 = new ArrayList<>();
for (Book book:books) {
if (book.getPublishingHouse().equals(publishingHouse)){
books1.add(book);
}
}
return books1;
}
private static List getBookByWriter(Scanner sc, List books) {
System.out.println("请输入要查询的作者:");
String writer = sc.next();
List books1 = new ArrayList<>();
for (Book book:books) {
if (book.getWriter().equals(writer)){
books1.add(book);
}
}
return books1;
}
private static Book getBookByBookId(Scanner sc, List books) {
System.out.println("请输入要查询的书号:");
String bookId = sc.next();
for (Book book:books) {
if (book.getBookId().equals(bookId)){
return book;
}
}
return null;
}
private static void addBook(Scanner sc, List books, IO io) throws IOException {
while (true){
Book b = new Book();
char ch = 'y';
System.out.println("请输入图书书号:");
String bookId = sc.next();
//判断书号是否重复
for (Book book:books) {
if (book.getBookId().equals(bookId)){
System.out.println("此书号已存在!!!");
ch = 'n';//重复
break;
}
}
if (ch == 'y'){
//书号没有重复
b.setBookId(bookId);
System.out.println("请输入书名:");
String bookName = sc.next();
b.setBookName(bookName);
System.out.println("请输入数量:");
int number = sc.nextInt();
b.setNumber(number);
System.out.println("请输入作者:");
String writer = sc.next();
b.setWriter(writer);
System.out.println("请输入出版社:");
String publishingHouse = sc.next();
b.setPublishingHouse(publishingHouse);
System.out.println("请输入出版时间:");
String publicationDate = sc.next();
b.setPublicationDate(publicationDate);
System.out.println("请输入定价:");
double price = sc.nextDouble();
b.setPrice(price);
books.add(b);
System.out.println("添加成功~~~");
}else {
System.out.println("此书号已存在~~~");
}
while(true){
System.out.println("是否继续添加?1---是;2---否");
int select = sc.nextInt();
if (select == 1){
break;
}else if (select == 2){
io.shoreBook(books);//将新增的读者信息存入文件中
return;
}else {
System.out.println("您的选择不能识别,请重新输入:");
}
}
}
}
private static void readersInformationManage(Scanner sc,List readers,IO io) throws IOException {
while(true){
System.out.println("================1、读者信息的添加================");
System.out.println("================2、读者信息的查询================");
System.out.println("================3、修改读者的信息================");
System.out.println("================4、删除读者的信息================");
System.out.println("================5、读者信息的排序================");
System.out.println("================6、读者信息的显示================");
System.out.println("================0、退出此界面=====================");
System.out.println("请选择操作:");
int select = sc.nextInt();
switch (select){
case 1:
addReader(sc,readers,io);//读者信息的添加
break;
case 2:
findReader(sc,readers);//读者信息的查询
break;
case 3:
modifyReader(sc,readers,io);//修改读者的信息
break;
case 4:
deleteReader(sc,readers,io);//删除读者的信息
break;
case 5:
sortReader(readers,io);//读者信息的排序
break;
case 6:
printReader(readers);//读者信息的显示
break;
case 0://退出此界面
return;
}
}
}
private static void printReader(List readers) {
if (readers.size() == 0){
System.out.println("系统中还每有录入读者信息~~~");
}
readers.forEach(System.out::println);
}
private static void deleteReader(Scanner sc, List readers, IO io) throws IOException {
while (true) {
System.out.println("请输入学号:");
String studentId = sc.next();
Reader r = getReaderByStudentId(studentId, readers);
//判断此学号对对应读者是否存在
if (r != null) {
//存在
System.out.println("请输入姓名:");
String studentName = sc.next();
//验证姓名是否一致
if (r.getStudentName().equals(studentName)) {
//一致,进行删除操作
int index = returnIndexByStudentId(studentId, readers);//获取此读者的下标
readers.remove(index);//进行删除操作
io.storeReader(readers);//将删除后的读者信息存入文档
System.out.println("删除完成~~~");
return;
}else {
//不一致,选择是否进行删除操作
System.out.println("对不起,您输入的名字不正确!!!");
System.out.println("是否继续验证操作?y/n");
while(true){
String select = sc.next();
if (select.equals("y")||select.equals("Y")){
break;
}else if (select.equals("n") || select.equals("N")){
return;
}else {
System.out.println("您的输入不能识别,请重新输入!!!");
}
}
}
}else {
//不存在,选择是否进行删除操作
System.out.println("查无此人!!!");
System.out.println("是否继续删除操作?y/n");
while(true) {
String select = sc.next();
if (select.equals("y") || select.equals("Y")) {
break;
} else if (select.equals("n") || select.equals("N")) {
return;
} else {
System.out.println("您的输入不能识别,请重新输入~~~");
}
}
}
}
}
private static void sortReader(List readers, IO io) throws IOException {
Collections.sort(readers);
io.storeReader(readers);
readers.forEach(System.out::println);
}
private static void addReader(Scanner sc, List readers,IO io) throws IOException {
while(true){
Reader r = new Reader();
System.out.println("请输入学号:");
String studentId = sc.next();
//判断学号是否重复
Reader reader = getReaderByStudentId(studentId,readers);
if (reader != null){
System.out.println("此学号已存在~~~");
}else {
r.setStudentId(studentId);
System.out.println("请输入姓名:");
String studentName = sc.next();
r.setStudentName(studentName);
System.out.println("请输入学院:");
String college = sc.next();
r.setCollege(college);
System.out.println("请输入专业:");
String specialty = sc.next();
r.setSpecialty(specialty);
System.out.println("请输入班级:");
System.out.println("格式:20xx级xx班");
String gradeAndClass = sc.next();
r.setGradeAndClass(gradeAndClass);
readers.add(r);
}
System.out.println("请问是否继续添加?y/n");
while (true){
String select = sc.next();
if (select.equals("n") || select.equals("N")){
io.storeReader(readers);//将新添加的信息存入文件中
return;
}else if (select.equals("y") || select.equals("Y")){
System.out.println("请继续添加操作~~~");
break;
}else {
System.out.println("抱歉,系统不能识别你的输入,请重新输入~~~");
}
}
}
}
private static void modifyReader(Scanner sc, List readers,IO io) throws IOException {
while(true){
System.out.println("请输入学号:");
String studentId = sc.next();
Reader r = getReaderByStudentId(studentId,readers);
if (r != null){
System.out.println("请输入姓名:");
String studentName = sc.next();
if (r.getStudentName().equals(studentName)){
System.out.println("可以进行修改操作了~~~");
int index = returnIndexByStudentId(studentId,readers);
while (true){
System.out.println("================1、修改学号================");
System.out.println("================2、修改姓名================");
System.out.println("================3、修改学院================");
System.out.println("================4、修改专业================");
System.out.println("================5、修改班级================");
System.out.println("================0、结束修改操作=============");
int select = sc.nextInt();
switch (select){
case 1:
System.out.println("请输入学号:");
String newStudentId = sc.next();
r.setStudentId(newStudentId);
break;
case 2:
System.out.println("请输入姓名:");
String studentName1 = sc.next();
r.setStudentName(studentName1);
break;
case 3:
System.out.println("请输入学院:");
String college = sc.next();
r.setCollege(college);
break;
case 4:
System.out.println("请输入专业:");
String specialty = sc.next();
r.setGradeAndClass(specialty);
break;
case 5:
System.out.println("请输入班级:");
System.out.println("格式:20xx级xx班");
String gradeAndClass = sc.next();
r.setGradeAndClass(gradeAndClass);
break;
case 0:
readers.set(index,r);
io.storeReader(readers);//将修改后的信息存入文件中
return;
}
}
}else {
System.out.println("对不起,您输入的名字不正确!!!");
System.out.println("是否继续验证操作?y/n");
while(true){
String select = sc.next();
if (select.equals("y")||select.equals("Y")){
break;
}else if (select.equals("n") || select.equals("N")){
return;
}else {
System.out.println("您的输入不能识别,请重新输入!!!");
}
}
}
}else {
System.out.println("对不起,此用户不存在!!!");
System.out.println("是否继续修改操作?y/n");
while(true){
String select = sc.next();
if (select.equals("y")||select.equals("Y")){
break;
}else if (select.equals("n") || select.equals("N")){
return;
}else {
System.out.println("您的输入不能识别,请重新输入~~~");
}
}
}
}
}
private static int returnIndexByStudentId(String studentId, List readers) {
for (int i = 0; i < readers.size(); i++) {
Reader r = readers.get(i);
if (r.getStudentId().equals(studentId)){
return i;
}
}
return -1;
}
private static void findReader(Scanner sc, List readers) {
while (true){
System.out.println("请选择你的查找方式:");
System.out.println("===============1、根据学号查询===============");
System.out.println("===============2、根据姓名查询===============");
System.out.println("===============3、根据学院查询===============");
System.out.println("===============4、根据专业查询===============");
System.out.println("===============5、根据班级查询===============");
System.out.println("===============0、退出查询功能===============");
System.out.println("请选操作:");
int select = sc.nextInt();
switch (select){
case 1:
System.out.println("请输入学号:");
String studentId = sc.next();
Reader r = getReaderByStudentId(studentId,readers);
if (r != null){
System.out.println(r);
}else {
System.out.println("查无此人!!!");
}
break;
case 2:
System.out.println("请输入姓名:");
String studentName = sc.next();
List readers1 = getReaderByStudentName(studentName,readers);
if (readers1.size() != 0){
for (Reader reader: readers1) {
System.out.println(reader);
}
}else {
System.out.println("查无此人!!!");
}
break;
case 3:
System.out.println("请输入学院:");
String college = sc.next();
List readers2 =getReaderByCollege(college,readers);
if (readers2.size() != 0){
for (Reader reader: readers2) {
System.out.println(reader);
}
}else {
System.out.println("查找不到此学院相关信息!!!");
}
break;
case 4:
System.out.println("请输入专业:");
String specialty = sc.next();
List readers3 = getReaderBySpecially(specialty,readers);
if (readers3.size() != 0){
for (Reader reader: readers3) {
System.out.println(reader);
}
}else {
System.out.println("查找不到辞职专业相关信息!!!");
}
break;
case 5:
System.out.println("请输入班级:");
System.out.println("格式:20xx级xx班");
String gradeAndClass = sc.next();
List readers4 = getReaderByGradeAndClass(gradeAndClass,readers);
if (readers4.size() != 0){
for (Reader reader: readers4) {
System.out.println(reader);
}
}else {
System.out.println("查询不到此班级相关信息!!!");
}
break;
case 0:
return;
}
}
}
private static List getReaderByGradeAndClass(String gradeAndClass, List readers) {
List readers1 = new ArrayList<>();
for (Reader reader:readers) {
if (reader.getGradeAndClass().equals(gradeAndClass)){
readers1.add(reader);
}
}
return readers1;
}
private static List getReaderBySpecially(String specialty, List readers) {
List readers1 = new ArrayList<>();
for (Reader reader:readers) {
if (reader.getSpecialty().equals(specialty)){
readers1.add(reader);
}
}
return readers1;
}
private static List getReaderByCollege(String college, List readers) {
List readers1 = new ArrayList<>();
for (Reader reader: readers) {
if (reader.getCollege().equals(college)){
readers1.add(reader);
}
}
return readers1;
}
private static List getReaderByStudentName(String studentName, List readers) {
List readers1 = new ArrayList<>();
for (Reader reader:readers) {
if (reader.getStudentName().equals(studentName)){
readers1.add(reader);
}
}
return readers1;
}
private static Reader getReaderByStudentId(String studentId, List readers) {
for (Reader reader:readers) {
if (reader.getStudentId().equals(studentId)){
return reader;
}
}
return null;
}
}



