项目说明
长期以来,人们使用传统的人工方式管理图书馆的日常业务,其操作流程比较烦琐。在借书时,读者首先将要借的书和借阅证交给工作人员,然后工作人员将每本书的信息卡片和读者的借阅证放在一个小格栏里,最后在借阅证和每本书贴的借阅条上填写借阅信息。在还书时,读者首先将要还的书交给工作人员,工作人员根据图书信息找到相应的书卡和借阅证,并填好相应的还书信息。太过于繁琐了!所以,我们需求设计一个图书管理系统来方便学生的借书和图书馆管理书籍。
本系统功能分为读者信息管理模块、图书信息管理模块、图书借阅管理模块、基础信息维护模块和用户管理模块。
读者信息管理:能够对读者的基本信息进行管理,包括新增读者,如学校新来一名教师,想要借书,就必须先添加读者信息;读者信息的修改,如学生转到别的专业,此时要修改学生的基本信息;删除读者的信息,比如某个学生中途退学了,可以将其信息删除。查询读者的信息,比如有同学拾到了一张借阅卡,卡上有学生的编号,通过此号来查询学生的联系电话,从而可以找到学生。
图书信息管理:能够对图书的基本信息进行管理,包括新增图书,学校每年会购进新书,此时需要将新书的信息录入系统中;图书信息的修改,如学生借书后将图书丢失,此时需要修改图书的总数量,使总数减1;删除图书,学校在购进新书的同时,每年会对过期的图书进行清理,不再提供借阅,此时就需要将这些图书的信息从系统中删除。查询图书的信息,比如要查看有哪些是Java相关的书籍或者指定ISBN号的图书等。
图书借阅信息管理:能够对图书的借阅信息进行记录,包括读者信息、图书信息、借阅时间等信息。
图书归还信息管理:能够对图书的借阅信息进行记录,包括读者信息、图书信息、归还时间、是否超期、罚金等信息。
系统用户信息管理:能够对系统用户的信息进行管理,包括增加新的系统操作用户,对当前系统用户的密码进行修改,以及删除某一用户。
项目内容
项目功能结构图:
项目功能如下:
(1)读者信息管理:包括读者信息添加和读者信息查询与修改功能。用户登录成功之后,可以浏览所有读者的信息,也可以检索特定读者的信息;同时,可以对读者信息进行维护,包括增加、删除及修改。具体信息包括读者类型(读者的类型决定着他可以借到书的最大数量和最大归还天数)、读者姓名、出生日期、性别、电话、所在院系、注册日期等。(相关存储数据可通过I/O流直接存在文件,可也直接在文件里读的数据)
(2)图书信息管理:包括图书信息添加和图书信息查询与修改功能。用户登录成功之后,可以浏览所有图书信息和检索特定图书的信息;也可以对图书信息进行维护。包括添加图书、删除图书以及修改图书信息。具体信息包括:图书ISBN、图书名称、作者、出版社、出版日期、印刷次数、单价、图书类别等。(相关存储数据可通过I/O流直接存在文件,可也直接在文件里读的数据)
(3)图书借阅管理:包括图书借阅和图书归还功能。图书借阅功能,先输入读者的编号,然后输入要借阅的图书的信息,记录系统当前时间即借阅时间;图书归还功能,输入读者的编号,选择其名下已借阅的图书,判断当前日期即归还日期与借阅日期的差值是否超过了规定的期限,计算罚金,从而进行图书的归还操作。具体信息包括:借阅日期、归还日期、罚金。由于要计算罚金,故需要知道该读者的读者类型,根据类型判断其可借图书天数、可借图书数量等。(相关存储数据可通过I/O流直接存在文件,可也直接在文件里读的数据)
(4)基础信息维护:包括图书类别设置、读者类别设置及罚金设置。图书类别设置,可以对图书的类别进行增加、删除、修改和查询;读者类别设置可以对读者的类别进行增加、删除、修改和查询;罚金设置,可以指定超期一天的罚金标准。(相关存储数据可通过I/O流直接存在文件,可也直接在文件里读的数据)
(5)用户管理:包括修改密码、用户添加和删除。修改密码,是指当前用户修改自己的密码;用户添加和删除,是对新增和去除系统用户时对用户信息的维护。(相关存储数据可通过I/O流直接存在文件,可也直接在文件里读的数据)
参考设计
整体代码模块
实体类
package librarysystem.domain;
import java.io.Serializable;
public class Book implements Serializable {
/*
图书ISBN、类别、图书名称、作者、出版社、出版日期、印刷次数、单价
String ISBN, String typename, String Bookname, String author,
String publish, String publishdate, Integer printtime, Double price
*/
//图书ISBN
private String ISBN;
//图书名称
private String bookname;
//作者
private String author;
//出版社
private String publish;
//出版日期
private String publishdate;
//印刷次数
private int printtime;
//单价
private double price;
//类别
private BookType typename;
public Book() {
}
public Book(String ISBN, String bookname, String author, String publish, String publishdate, int printtime, double price, BookType typename) {
this.ISBN = ISBN;
this.bookname = bookname;
this.author = author;
this.publish = publish;
this.publishdate = publishdate;
this.printtime = printtime;
this.price = price;
this.typename = typename;
}
public String getISBN() {
return ISBN;
}
public void setISBN(String ISBN) {
this.ISBN = ISBN;
}
public String getBookname() {
return bookname;
}
public void setBookname(String bookname) {
this.bookname = bookname;
}
public String getAuthor() {
return author;
}
public void setAuthor(String author) {
this.author = author;
}
public String getPublish() {
return publish;
}
public void setPublish(String publish) {
this.publish = publish;
}
public String getPublishdate() {
return publishdate;
}
public void setPublishdate(String publishdate) {
this.publishdate = publishdate;
}
public int getPrinttime() {
return printtime;
}
public void setPrinttime(int printtime) {
this.printtime = printtime;
}
public double getPrice() {
return price;
}
public void setPrice(double price) {
this.price = price;
}
public BookType getTypename() {
return typename;
}
public void setTypename(BookType typename) {
this.typename = typename;
}
@Override
public String toString() {
return "Book{" +
"ISBN='" + ISBN + '\'' +
", bookname='" + bookname + '\'' +
", author='" + author + '\'' +
", publish='" + publish + '\'' +
", publishdate='" + publishdate + '\'' +
", printtime=" + printtime +
", price=" + price +
", typename=" + typename +
'}';
}
}
读者信息管理
package librarysystem.dao;
import librarysystem.domain.Reader;
import librarysystem.domain.ReaderType;
import librarysystem.tool.BookException;
import librarysystem.tool.tool;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
public class ReaderDao {
public static void main(String[] args) throws IOException, ClassNotFoundException, BookException {
}
//打印信息
public static void printInfor(List<Reader> list){
tool.storeLog("打印读者信息");
System.out.println("编号\t姓名\t类型\t年龄\t性别\t\t电话\t\t\t院系\t\t\t\t注册时间");
for (Reader r:list){
System.out.println(r.getReaderid()+" "+r.getName()+" "+r.getType().getTypename()+" "+r.getAge()+" "+r.getSex()+" "+r.getPhone()+" "+r.getDepart()+" "+r.getRegdat());
}
}
//初始化
public static void initialization() throws IOException, ClassNotFoundException {
tool.storeLog("读者信息初始化");
File file=new File("C:\\Users\\潇霸霸\\IdeaProjects\\untitled\\src\\librarysystem\\file\\reader.txt");
Reader reader=new Reader("1","秦潇","男",21,"12346874614","大数据与智能工程学院","2021-09-01",new ReaderType("1","学生",5,5));
List<Reader> list=new ArrayList<>();
list.add(reader);
tool.returnFile(list,file);
}
//读者信息添加
public static int insertReader(String id, List<ReaderType> list, String name, String age, String sex, String phone, String dept, String reg) throws BookException, IOException, ClassNotFoundException {
tool.storeLog("读者信息添加");
Reader reader=new Reader(id,name,sex,Integer.parseInt(age),phone,dept,reg,list.get(0));
File file=new File("C:\\Users\\潇霸霸\\IdeaProjects\\untitled\\src\\librarysystem\\file\\reader.txt");
Object o = tool.readFile(file);
List<Reader> readers=(List<Reader>) o;
boolean flag=false;
for (Reader r:readers){
String readerid = r.getReaderid();
if (readerid.equals(id)){
flag=true;
}
}
if (flag){
tool.logging("发现了异常,该编号读者已存在");
throw new BookException("该编号读者已存在");
}else {
readers.add(reader);
tool.returnFile(readers,file);
return Integer.parseInt(id);
}
}
//查询读者信息
public static List<Reader> selectReader() throws IOException, ClassNotFoundException {
tool.storeLog("查询读者信息");
File file=new File("C:\\Users\\潇霸霸\\IdeaProjects\\untitled\\src\\librarysystem\\file\\reader.txt");
Object o=null;
try {
o=tool.readFile(file);
}catch (Exception e){
System.out.println(e.getMessage());
}
List<Reader> list=(List<Reader>)o;
return list;
}
//查询读者信息通过ID
public static List<Reader> selectReaderById(String id) throws IOException, ClassNotFoundException, BookException {
tool.storeLog("查询读者信息Id");
File file=new File("C:\\Users\\潇霸霸\\IdeaProjects\\untitled\\src\\librarysystem\\file\\reader.txt");
Object o=tool.readFile(file);
List<Reader> list=(List<Reader>)o;
List<Reader> readerList=new ArrayList<>();
boolean flag=false;
for (Reader r:list){
String readerid = r.getReaderid();
if (readerid.equals(id)){
readerList.add(r);
flag=true;
}
}
if (flag){
return readerList;
}else {
tool.logging("发现了异常,该编号的读者不存在");
throw new BookException("该编号的读者不存在");
}
}
//查询读者信息通过名字
public static List<Reader> selectReaderByName(String name) throws IOException, ClassNotFoundException, BookException {
tool.storeLog("查询读者信息姓名");
File file=new File("C:\\Users\\潇霸霸\\IdeaProjects\\untitled\\src\\librarysystem\\file\\reader.txt");
Object o=tool.readFile(file);
List<Reader> list=(List<Reader>)o;
List<Reader> readerList=new ArrayList<>();
boolean flag=false;
for (Reader r:list){
String readerName = r.getName();
if (readerName.equals(name)){
readerList.add(r);
flag=true;
}
}
if (flag){
return readerList;
}else {
tool.logging("发现了异常,该姓名的读者不存在");
throw new BookException("该姓名的读者不存在");
}
}
//查询读者信息通过类型
public static List<Reader> selectReaderByType(String type) throws IOException, ClassNotFoundException, BookException {
tool.storeLog("查询读者信息类型");
File file=new File("C:\\Users\\潇霸霸\\IdeaProjects\\untitled\\src\\librarysystem\\file\\reader.txt");
Object o=tool.readFile(file);
List<Reader> list=(List<Reader>)o;
List<Reader> readerList=new ArrayList<>();
boolean flag=false;
for (Reader r:list){
String readerType=r.getType().getTypename();