Library management system

Posted by php3ch0 on Tue, 30 Nov 2021 04:37:38 +0100

Project description

  •   For a long time, people use the traditional manual way to manage the daily business of the library, and its operation process is cumbersome. When borrowing a book, the reader first gives the book to be borrowed and the borrowing card to the staff, then the staff puts the information card of each book and the reader's borrowing card in a small column, and finally fills in the borrowing information on the borrowing card and the borrowing slip pasted on each book. When returning books, readers first give the books to be returned to the staff. The staff find the corresponding book card and borrowing card according to the book information, and fill in the corresponding book return information. Too cumbersome! Therefore, we need to design a library management system to facilitate students' borrowing and library management.
  • The system functions are divided into reader information management module, book information management module, book borrowing management module, basic information maintenance module and user management module.
  • Reader information management: it can manage the basic information of readers, including new readers. For example, if a new teacher wants to borrow a book, he must first add reader information; Modification of readers' information. If students transfer to other majors, the basic information of students should be modified at this time; Delete the reader's information. For example, if a student drops out of school, his information can be deleted. Query the reader's information. For example, some students found a borrowing card with the student's number on it. Through this number, they can query the student's contact number, so as to find the student.
  •   Library Information Management: be able to manage the basic information of books, including new books. The school will buy new books every year. At this time, the information of new books needs to be entered into the system; For the modification of book information, if students lose books after borrowing books, it is necessary to modify the total number of books to reduce the total number by 1; Delete books. While purchasing new books, the school will clean up the expired books every year and no longer provide borrowing. At this time, it is necessary to delete the information of these books from the system. Query the information of books, such as checking which books are Java related or books with specified ISBN number, etc.
  •   Book borrowing information management: it can record the borrowing information of books, including reader information, book information, borrowing time and other information.
  •   Book return information management: it can record the borrowing information of books, including reader information, book information, return time, whether it is overdue, fine and other information.
  •   System user information management: it can manage the information of system users, including adding new system operation users, modifying the password of current system users, and deleting a user.

Project content

The project functions are as follows:
(1) Reader information management: including reader information addition and reader information query and modification functions. After logging in successfully, users can browse the information of all readers or retrieve the information of specific readers; At the same time, you can maintain the reader information, including adding, deleting and modifying. The specific information includes the type of Reader (the type of reader determines the maximum number of books he can borrow and the maximum return days), the reader's name, date of birth, gender, telephone, Department, registration date, etc. (relevant stored data can be directly stored in the file through I/O stream, and can also be read directly in the file)
(2) Book information management: including book information addition and book information query and modification functions. After logging in successfully, users can browse all book information and retrieve the information of specific books; You can also maintain book information. Including adding books, deleting books and modifying book information. Specific information includes: Book ISBN, book name, author, publishing house, publishing date, printing times, unit price, book category, etc. (relevant stored data can be directly stored in the file through I/O stream, and can also be read directly in the file)
(3) Book borrowing management: including book borrowing and book return functions. Book borrowing function, first enter the reader's number, then enter the information of the book to be borrowed, and record the current time of the system, that is, the borrowing time; Book return function: input the reader's number, select the borrowed books under its name, judge whether the current date, that is, the difference between the return date and the borrowing date exceeds the specified period, and calculate the penalty, so as to return the books. Specific information includes: borrowing date, return date and penalty. To calculate the penalty, you need to know the reader type of the reader, and judge the number of books that can be borrowed and the number of books that can be borrowed according to the type. (relevant stored data can be directly stored in the file through I/O stream, and can also be read directly in the file)
(4) Basic information maintenance: including book category setting, reader category setting and penalty setting. Book category settings: you can add, delete, modify and query book categories; Reader category settings can add, delete, modify and query reader categories; Penalty setting: you can specify the penalty standard for one day overdue. (relevant stored data can be directly stored in the file through I/O stream, and can also be read directly in the file)
(5) User management: including password modification, user addition and deletion. Modify password means that the current user modifies his own password; User addition and deletion are the maintenance of user information when adding and removing system users. (relevant stored data can be directly stored in the file through I/O stream, and can also be read directly in the file)

Example code:

It mainly explains the code snippet of key borrowing operation

Entity classes for borrowing and returning books:  

package domain;

import java.io.Serializable;
import java.util.HashSet;
import java.util.Objects;

public class BorrowDomain implements Serializable {
    private static final long serialVersionUID = 42L;
    private Reader reader;
    private HashSet<Book> books;
    private String borrowdate;

    public BorrowDomain(Reader reader, HashSet<Book> books, String borrowdate) {
        this.reader = reader;
        this.books = books;
        this.borrowdate = borrowdate;
    }

    public BorrowDomain() {
    }

    public static long getSerialVersionUID() {
        return serialVersionUID;
    }

    public Reader getReader() {
        return reader;
    }

    public void setReader(Reader reader) {
        this.reader = reader;
    }

    public HashSet<Book> getBooks() {
        return books;
    }

    public void setBooks(HashSet<Book> books) {
        this.books = books;
    }

    public String getBorrowdate() {
        return borrowdate;
    }

    public void setBorrowdate(String borrowdate) {
        this.borrowdate = borrowdate;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        BorrowDomain that = (BorrowDomain) o;
        return Objects.equals(reader, that.reader) &&
                Objects.equals(books, that.books) &&
                Objects.equals(borrowdate, that.borrowdate);
    }

    @Override
    public int hashCode() {
        return Objects.hash(reader, books, borrowdate);
    }
}

  

 

package domain;

import java.io.Serializable;
import java.util.Objects;

public class ReturnBook implements Serializable {
    private static final long serialVersionUID = 42L;
    private BorrowDomain borrow;
    private String returnbook;
    private int moeny;
    private String book;

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        ReturnBook that = (ReturnBook) o;
        return moeny == that.moeny &&
                Objects.equals(borrow, that.borrow) &&
                Objects.equals(returnbook, that.returnbook) &&
                Objects.equals(book, that.book);
    }

    @Override
    public int hashCode() {
        return Objects.hash(borrow, returnbook, moeny, book);
    }

    public static long getSerialVersionUID() {
        return serialVersionUID;
    }

    public BorrowDomain getBorrow() {
        return borrow;
    }

    public void setBorrow(BorrowDomain borrow) {
        this.borrow = borrow;
    }

    public String getReturnbook() {
        return returnbook;
    }

    public void setReturnbook(String returnbook) {
        this.returnbook = returnbook;
    }

    public int getMoeny() {
        return moeny;
    }

    public void setMoeny(int moeny) {
        this.moeny = moeny;
    }

    public String getBook() {
        return book;
    }

    public void setBook(String book) {
        this.book = book;
    }

    public ReturnBook(BorrowDomain borrow, String returnbook, int moeny, String book) {
        this.borrow = borrow;
        this.returnbook = returnbook;
        this.moeny = moeny;
        this.book = book;
    }

    public ReturnBook() {
    }
}

Operation class of borrowing and returning books:  

package Service;

import domain.Book;
import domain.BorrowDomain;
import domain.Reader;
import domain.ReturnBook;
import org.w3c.dom.ls.LSOutput;

import java.io.*;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashSet;
import java.util.Properties;

public class BorrrowBookService {
   private static HashSet<BorrowDomain> hashSets=new HashSet<>();
   private static HashSet<ReturnBook> returnBookHashSet=new HashSet<>();
   public void getAllBorrow() throws IOException, ClassNotFoundException {
       ObjectInputStream ois = new ObjectInputStream(new FileInputStream("TheTeam_2\\src\\TypeTxt\\Borrow.txt"));
       Object o = ois.readObject();
       HashSet<BorrowDomain> hs=(HashSet<BorrowDomain>) o;
       for(BorrowDomain b:hs){
           for(Book books: b.getBooks()) {
               if(books==null) {
                   System.out.println("Student number:" + b.getReader().getReaderid() + " full name:" + b.getReader().getName() + " category:" + b.getReader().getType().getTypename()+"  Borrowing situation:"+"No borrowing");
               }
               else {
                   System.out.println("Student number:" + b.getReader().getReaderid() + " full name:" + b.getReader().getName() + " category:" + b.getReader().getType().getTypename()+"  Borrowing title:"+books.getBookname()+" hours of loan service:"+b.getBorrowdate());
               }
           }
           System.out.println("=====================================");
       }
       TSUtility.readReturn();

   }
   public void borrowBook() throws IOException, ClassNotFoundException {
       new ReaderService().getallReader();
       Reader r=selectBorrowByid();
       HashSet<Book> borrowBookList = new HashSet<>();



       ObjectInputStream readIO = new ObjectInputStream(new FileInputStream("TheTeam_2\\src\\TypeTxt\\Borrow.txt"));
       Object o1 = readIO.readObject();
       HashSet<BorrowDomain> hb=(HashSet<BorrowDomain>) o1;
       readIO.close();
       for(BorrowDomain b:hb){
               if(b.getReader().equals(r)) {
                   for (Book xb : b.getBooks()) {
                       borrowBookList.add(xb);
                   }
               }
               else {
                   hashSets.add(b);
               }
       }


       new BookService().gatAllBook();
       System.out.println("Please enter the book number you want to borrow:");
       String borrowId=TSUtility.readKeyBoard(20,false);
       ObjectInputStream ois = new ObjectInputStream(new FileInputStream("TheTeam_2\\src\\TypeTxt\\Book.txt"));
       Object o = ois.readObject();
       HashSet<Book> newSet=(HashSet<Book>) o;
       ois.close();
       int num=0;
       for (Book b:newSet){
           if(b.getBookid().equals(borrowId)){
               if(borrowBookList.size()>=r.getType().getMaxborrownum()){
                   System.out.println("The maximum number of books has been reached. You can't borrow any more");
               }
               else {
                   borrowBookList.add(b);
                   num++;
                   Date date = new Date();
                   SimpleDateFormat spd = new SimpleDateFormat("yyy year MM month dd day HH:mm:ss");
                   String s = spd.format(date);
                   BorrowDomain bd = new BorrowDomain(r, borrowBookList, s);
                   hashSets.add(bd);
                   ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream("TheTeam_2\\src\\TypeTxt\\Borrow.txt"));
                   oos.writeObject(hashSets);
                   oos.close();
                   System.out.println("Borrowing succeeded");

                   BufferedWriter bw = new BufferedWriter(new FileWriter("TheTeam_2\\src\\Log.txt",true));
                   Date date2 = new Date();
                   SimpleDateFormat spd2= new SimpleDateFormat("yyy year MM month dd day HH:mm:ss");
                   String dengluTime=spd.format(date2);
                   bw.write(dengluTime+"   readers:"+r.getName()+" Borrowed books:"+b.getBookname());
                   bw.newLine();
                   bw.flush();
                   bw.close();

               }
           }
       }
       if(num==0){
           System.out.println("The book you are looking for does not exist");
       }

   }
   public Reader selectBorrowByid() throws IOException, ClassNotFoundException {
       System.out.println("Please enter the reader's student number");
       String id=TSUtility.readKeyBoard(11,false);
       ObjectInputStream ois = new ObjectInputStream(new FileInputStream("TheTeam_2\\src\\TypeTxt\\Reader.txt"));
       Object o = ois.readObject();
       HashSet<Reader> newArr=(HashSet<Reader>) o;
       int num=0;
       for (Reader r:newArr){
           if(r.getReaderid().equals(id)){
               num++;
               return r;
           }
       }
       if(num==0) {
           System.out.println("The student of this student number was not found!");
       }
       TSUtility.readReturn();
       return null ;
   }
   public void returnBook() throws IOException, ClassNotFoundException, ParseException {
       getAllBorrow();
       System.out.println("Please enter the reader's student number");
       String id=TSUtility.readKeyBoard(11,false);
//       Reader reader=null;
       BorrowDomain bd=null;

       ObjectInputStream ois = new ObjectInputStream(new FileInputStream("TheTeam_2\\src\\TypeTxt\\Borrow.txt"));
       Object o = ois.readObject();
       HashSet<BorrowDomain> newArr=(HashSet<BorrowDomain>) o;
       int num=0;
       ois.close();
       for (BorrowDomain rr:newArr){
           if(rr.getReader().getReaderid().equals(id)){
               num++;
               bd=rr;
//               reader=rr.getReader();
               for(Book books:rr.getBooks()) {
                   System.out.println("Student number:" + rr.getReader().getReaderid() + " full name:" + rr.getReader().getName() + " category:" + rr.getReader().getType().getTypename() + "  Borrowing title:" + books.getBookname() + " hours of loan service:" + rr.getBorrowdate());
               }
           }
       }
       if(num==0) {
           System.out.println("The student's borrowing information was not found!");
       }
       if(bd!=null){
           System.out.println("Please enter the name of the book to return");
           String returnbookname=TSUtility.readKeyBoard(20,false);
           int numnum=0;
           for(Book boo:bd.getBooks()){
               if(boo.getBookname().equals(returnbookname)){
                   numnum++;

                   ObjectInputStream oiss = new ObjectInputStream(new FileInputStream("TheTeam_2\\src\\TypeTxt\\Return.txt"));
                   Object q = oiss.readObject();
                   HashSet<ReturnBook> hs=(HashSet<ReturnBook>) q;
                   oiss.close();
                   for(ReturnBook rb:hs){
                       returnBookHashSet.add(rb);
                   }

                 /*  Date date = new Date();
                   SimpleDateFormat sad= new SimpleDateFormat("yyyy MM dd, HH:mm:ss ");
                   String back=sad.format(date);*/
                   System.out.println("Please enter return date(yyyy year MM month dd day)");
                   String back=TSUtility.readKeyBoard(21,false);
                   SimpleDateFormat sad= new SimpleDateFormat("yyyy year MM month dd day");
                   Date date=sad.parse(back);

                   String borrowtime=bd.getBorrowdate();
                   SimpleDateFormat spd = new SimpleDateFormat("yyyy year MM month dd day HH:mm:ss");
                   Date dd = spd.parse(borrowtime);
                   long time=(date.getTime()-dd.getTime())/(1000*3600*24);
                   int givemoney=0;
                   System.out.println(time);
                   if(time>bd.getReader().getType().getLimit()){
                       Properties prp = new Properties();
                       BufferedInputStream bis = new BufferedInputStream(new FileInputStream("TheTeam_2\\src\\TypeTxt\\Money.txt"));
                       prp.load(bis);
                       bis.close();
                       givemoney=(int)(time-bd.getReader().getType().getLimit())*Integer.parseInt(prp.getProperty(bd.getReader().getType().getTypename()));
                       System.out.println(givemoney);
                   }
                   ReturnBook returnBook = new ReturnBook(bd, back, givemoney,boo.getBookname());
                   returnBookHashSet.add(returnBook);
                   ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream("TheTeam_2\\src\\TypeTxt\\Return.txt"));
                   oos.writeObject(returnBookHashSet);
                   oos.close();

                   HashSet<Book> returnBookList = new HashSet<>();
                   ObjectInputStream readIO = new ObjectInputStream(new FileInputStream("TheTeam_2\\src\\TypeTxt\\Borrow.txt"));
                   Object o1 = readIO.readObject();
                   HashSet<BorrowDomain> hb=(HashSet<BorrowDomain>) o1;
                   readIO.close();
                   for(BorrowDomain b:hb){
                       if(b.getReader().equals(bd.getReader())) {
                           if(b.getBooks().size()>1) {
                               for (Book xb : b.getBooks()) {
                                   if (!xb.getBookname().equals(boo.getBookname())) {
                                       returnBookList.add(xb);
                                   }
                               }
                               hashSets.add(new BorrowDomain(b.getReader(), returnBookList, b.getBorrowdate()));
                           }
                       }
                       else {
                           hashSets.add(b);
                       }
                   }
                   ObjectOutputStream oos1 = new ObjectOutputStream(new FileOutputStream("TheTeam_2\\src\\TypeTxt\\Borrow.txt"));
                   oos1.writeObject(hashSets);
                   oos1.close();


                   System.out.println("Return successful");

                   BufferedWriter bw = new BufferedWriter(new FileWriter("TheTeam_2\\src\\Log.txt",true));
                   Date date3 = new Date();
                   SimpleDateFormat spd3= new SimpleDateFormat("yyy year MM month dd day HH:mm:ss");
                   String dengluTime=spd.format(date3);
                   bw.write(dengluTime+"   readers:"+bd.getReader().getName()+" Returned the book:"+returnbookname);
                   bw.newLine();
                   bw.flush();
                   bw.close();

               }
           }
           if(numnum==0){
               System.out.println("The book does not exist");
           }
           TSUtility.readReturn();
       }

   }
   public void lookReturn() throws IOException, ClassNotFoundException {
       ObjectInputStream ois = new ObjectInputStream(new FileInputStream("TheTeam_2\\src\\TypeTxt\\Return.txt"));
       Object o = ois.readObject();
       HashSet<ReturnBook> hs = (HashSet<ReturnBook>) o;
       ois.close();
       for (ReturnBook rb:hs){
           System.out.println("Student name:"+rb.getBorrow().getReader().getName()+" Borrow books:"+rb.getBook()+" Borrowing date:"+rb.getBorrow().getBorrowdate()+" Return date :"+rb.getReturnbook()+" Late payment:"+rb.getMoeny());
       }
       TSUtility.readReturn();
   }

    public static void main(String[] args) throws IOException, ClassNotFoundException, ParseException {
        new BorrrowBookService().returnBook();
    }

}

main interface

package View;

import Service.*;

import java.io.*;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

public class TheMainView {
    public static void main(String[] args) throws IOException, ClassNotFoundException, ParseException {
        System.out.println("******************************");
        System.out.println("*                            *");
        System.out.println("******* Welcome to the library management system*******");
        System.out.println("*                            *");
        System.out.println("******************************");
        System.out.println("*                            *");
        System.out.println("*                            *");
        System.out.println("*     -Please log in first——        *");

        String UseName=null;
        UsersService use = new UsersService();
        for(int i=1;i<=3;i++){
            boolean s=use.check();
            if(s==true){
                UseName=use.getname();
                BufferedWriter bw = new BufferedWriter(new FileWriter("TheTeam_2\\src\\Log.txt",true));
                Date date = new Date();
                SimpleDateFormat  spd= new SimpleDateFormat("yyy year MM month dd day HH:mm:ss");
                String dengluTime=spd.format(date);
                bw.write(dengluTime+"   user:"+UseName+" Entered the library management system");
                bw.newLine();
                bw.flush();
                bw.close();
               break;
            }
            else {
                if(i==3){
                    System.out.println("Number depletion");
                    System.exit(0);
                }
                System.out.println("You still have"+(3-i)+"Second chance");
            }
        }

        boolean flag=true;
        while (flag){
            System.out.println("1.Reader information management");
            System.out.println("2.Library information management");
            System.out.println("3.Book borrowing information management");
            System.out.println("4.Basic information maintenance");
            System.out.println("5.user management ");
            System.out.println("6.sign out");
            int i=TSUtility.readInt();
            if(i==1){
                new ReaderView().meth();
            }
            else if(i==2){
                new BookView().view();
            }
            else if(i==4){
                boolean flag2=true;
                while (flag2) {
                    System.out.println("1.Reader type management");
                    System.out.println("2.Book type management");
                    System.out.println("3.Fine management");
                    System.out.println("4.sign out");
                    int i2 = TSUtility.readInt();
                    if (i2 == 1) {
                        new ReaderTypeView().view();
                    }
                    else if (i2 == 2) {
                        new BookTypeView().view();
                    }
                    else if (i2 == 4) {
                        flag2=false;
                    }
                    else if(i2==3){
                        boolean f=true;
                        while (f) {
                            System.out.println("1.Penalty modification");
                            System.out.println("2.Penalty view");
                            System.out.println("3.sign out");
                            int ii=TSUtility.readInt();
                            if(ii==1){
                                new MoneyService().changeMoney();
                            }
                            else if(ii==2){
                                new MoneyService().look();
                            }
                            else if(ii==3){
                                f=false;
                            }
                            else {
                                System.out.println("Wrong choice");
                            }
                        }
                    }
                    else {
                        System.out.println("Your input is incorrect, please re-enter");
                    }
                }
            }
            else if(i==3){
                new BorrowView().view();
            }
            else if(i==5){
                boolean ss=true;
                while (ss) {
                    System.out.println("1.User increase");
                    System.out.println("2.User delete");
                    System.out.println("3.View user");
                    System.out.println("4.Modify user information");
                    System.out.println("5.sign out");
                    int qq = TSUtility.readInt();
                    if (qq == 1) {
                        use.addUser();
                    }
                    else if (qq == 2) {
                       use.delecteUsers();
                    }
                    else if (qq == 3) {
                        use.getAllUser();
                    }
                    else if(qq==4){
                        use.changeUser();
                    }
                    else if(qq==5){
                        ss=false;
                    }
                    else {
                        System.out.println("Your input is incorrect, please re-enter");
                    }
                }
            }
            else if(i==6){
                BufferedWriter bw = new BufferedWriter(new FileWriter("TheTeam_2\\src\\Log.txt",true));
                Date date = new Date();
                SimpleDateFormat  spd= new SimpleDateFormat("yyy year MM month dd day HH:mm:ss");
                String dengluTime=spd.format(date);
                bw.write("-------------------------------");
                bw.newLine();
                bw.flush();
                bw.close();

                flag=false;
            }
            else {
                System.out.println("Input error, please re-enter");
            }
        }
    }
}

Topics: Java Programming string