当前位置:网站首页>Library management system

Library management system

2022-07-06 14:16:00 One skim and one cross

Preface

       I've just started to learn Java, The basic functions of the whole system have been realized , But in terms of code , The code of the whole program is more complex , You can also optimize and improve the code , Yes IO The understanding and mastery of flow is not proficient . In addition, there are many deficiencies in this program and the author's handwriting , Welcome your comments and suggestions .

Text

      There are four classes in one package


      Overall functional composition and implementation
 Insert picture description here

UI Class to call the method of system startup
BookInfo Class storage below Book information
ReaderInfo Class storage below Reader information
BookBorrow Class storage below Borrowing query information

Menu and system startup

    // Create three classes Arraylist
    static ArrayList<BookInfo> booklist = new ArrayList<>();
    static ArrayList<ReaderInfo> readlist = new ArrayList<>();
    static ArrayList<BookBorrow> borrowlist = new ArrayList<>();
public   static void Show()// menu 
    {
    
        System.out.println("****************************************************************");
        System.out.println("——————————————————————— The system starts ———————————————————————————————————");
        System.out.println("——————0、 Exit the system ————————————————————————————————————————————————");
        System.out.println("——————1、 Add book information ( Book number 、 Title 、 author 、 Press. 、 Number of Libraries 、 pricing )——————————");
        System.out.println("——————2、 Book information inquiry ( According to the book title 、 The author's name 、 Press, etc ———————————————");
        System.out.println("——————3、 Book information sorting ( By book number 、 Book titles are sorted in ascending order )————————————————————");
        System.out.println("——————4、 Book information modification 、 Delete ( Modify and delete books by book number or title )————————————");
        System.out.println("——————5、 Add reader information ( Including student ID 、 full name 、 college 、 Professional classes, etc )—————————————————");
        System.out.println("——————6、 Reader information query ( According to the student id 、 full name 、 Professional classes, etc )—————————————————");
        System.out.println("——————7、 Reader information sorting ( According to the student id 、 Colleges, etc. are sorted in ascending order )—————————————————————");
        System.out.println("——————8、 Reader information modification 、 Delete ( According to the student id + Name to modify and delete reader information )——————————");
        System.out.println("——————9、 Book borrowing ( Enter the student id + Book number )————————————————————————————————————");
        System.out.println("——————10、 Book return ( Enter the student id + Book number )———————————————————————————————————");
        System.out.println("——————11、 Book borrowing inquiry ( By student number 、 Title 、 Colleges and so on )————————————————");
        System.out.println("——————————————————————— Please select function items ————————————————————————————");
        System.out.println("*****************************************************************");
    }
    public static void main(String[] args) throws Exception {
    
        Scanner sc = new Scanner(System.in);
        InBookInfoFile();
        InReaderFile();
        InBorrowFile();
        while (true) {
    
            Show();
            int flag = sc.nextInt();
            switch (flag) {
    
                case 0:
                    OutReader();
                    OutBookBorrow();
                    OutBookInformation();
                    System.out.println(" Exit the book borrowing system ");
                    System.exit (0);
                case 1:
                    AddBook(); //  Add book information 
                    break;
                case 2:
                    PrintBook(booklist);//  Book information inquiry 
                    break;
                case 3:
                    SortBook(booklist);// Book information sorting 
                    break;
                case 4:
                    ChangeBook(booklist);// Book information modification 
                    break;
                case 5:
                    AddReader();     //  Student information added 
                    break;
                case 6:
                    PrintReader();    // Student information inquiry 
                    break;
                case 7:
                    SortStu();//  Student information ranking 
                    break;
                case 8:
                    ChaReStu();  // Modification of student information 、 Delete 
                    break;
                case 9:
                    BorrowBook(); // Book borrowing 
                    break;
                case 10:
                    BackBook();// Book return 
                    break;
                case 11:PriBookReader();// Book borrowing 、 Inquire about 
                    break;

                default:
                    System.out.println(" The data is wrong , Please re-enter ");
                    break;
            }

        }
    }

Refer to the following to establish the corresponding class , Then call the function through the above

The book

Create a Book Class

public class BookInfo {
    
    String BookNum; // Book number 
    String BookName;// Title 
    String BookAuthor; //  author 
    String Publisher; // Press. 
    String PublishTime; // Publication date 
    int BookCount;  // Number of books stored 
    double Price;// pricing 
    public BookInfo(String bookNum, String bookName, String bookAuthor, String publisher, String publishTime, int bookCount, double price) {
    
        BookNum = bookNum;
        BookName = bookName;
        BookAuthor = bookAuthor;
        Publisher = publisher;
        PublishTime = publishTime;
        BookCount = bookCount;
        Price = price;
    }
    public void setBookInfo(String bookNum, String bookName, String bookAuthor, String publisher, String publishTime, int bookCount, double price) {
    
        BookNum = bookNum;
        BookName = bookName;
        BookAuthor = bookAuthor;
        Publisher = publisher;
        PublishTime = publishTime;
        BookCount = bookCount;
        Price = price;
    }
    public String getBookNum() {
    
        return BookNum;
    }
    public void setBookNum(String bookNum) {
    
        BookNum = bookNum;
    }// The rest can be constructed directly through the editor ( I won't repeat )
    public String toString()// Output entry 
    {
    
        return (" Book number :" + BookNum + "\t" + " Title :" + BookName
                + "\t" + " author :" + BookAuthor + "\t" + " Press. :" + Publisher
                + "\t" + " Publication date :" + PublishTime + "\t" + " Number of Libraries :" + BookCount
                + "\t" + " pricing :" + Price);
    }
}

Book information adding function

Including book number 、 Title 、 author 、 Press. 、 Number of Libraries 、 Pricing, etc .

 public static void AddBook()// Add book information 
    {
    

        while (true) {
    
            System.out.println(" At present, there is " + booklist.size() + " A Book of sorts !");
            Scanner sc = new Scanner(System.in);
            System.out.println(" Please enter the book number ");
            String ID = sc.next();
            System.out.println(" Please enter the title of the book 、 author 、 Press. 、 Publication date ");
            String bookname = sc.next();
            String author = sc.next();
            String publisher = sc.next();
            String publishTime = sc.next();
            System.out.println(" Please enter the storage quantity ");
            int BookCount = sc.nextInt();
            System.out.println(" Please enter the pricing ");
            double Price = sc.nextDouble();
            BookInfo book = new BookInfo(ID, bookname, author, publisher, publishTime, BookCount, Price);
            booklist.add(book);
            System.out.println(" Book added successfully ");
            System.out.println("1、 Continue to add \t2、 End adding ");
            int chioce = sc.nextInt();
            if (chioce == 1) {
    
                continue;
            }
            if (chioce == 2) {
    
                break;
            }
        }
    }

Book information inquiry function

According to the book title , By author's name , Query by publishing house .

  public static void PrintBook(ArrayList<BookInfo> booklist)// Book information inquiry 
    {
    
        Scanner sc = new Scanner(System.in);
        while (true) {
    
            int flag = 0;// Mark 
            System.out.println(" Please select the query method ");
            System.out.println("1、 Search by title  2、 Search by author name  3、 Query by publishing house ");
            int num1 = sc.nextInt();
            switch (num1) {
    
                case 1:
                    System.out.println(" Please enter the title of the book you are looking for :");
                    String bookname = sc.next();

                    for (int i = 0; i < booklist.size(); i++) {
    
                        BookInfo B = booklist.get(i);
                        if (B.getBookName().equals(bookname)) {
    
                            System.out.println(" Book number :" + B.getBookNum() + "\t" + " Title :" + B.BookName
                                    + "\t" + " author :" + B.getBookAuthor() + "\t" + " Press. :" + B.getPublisher()
                                    + "\t" + " Publication date :" + B.getPublishTime() + "\t" + " Number of Libraries :" + B.getBookCount()
                                    + "\t" + " pricing :" + B.getPrice());
                            flag = 1;
                        }

                    }
                    if (flag == 0) {
    
                        System.out.println(" There is no such book , Please re-enter ");
                    }
                    if (flag == 1) {
    
                        System.out.println("1、 Continue checking  2、 sign out ");
                        int choice = sc.nextInt();
                        if (choice == 1) {
    
                            break;
                        }
                        if (choice == 2) {
    
                            return;
                        }
                    }
                    break;
                case 2:
                    System.out.println(" Please enter the author name you want to find :");
                    String author = sc.next();
                    for (int i = 0; i < booklist.size(); i++) {
    
                        BookInfo B = booklist.get(i);
                        if (B.getBookAuthor().equals(author)) {
    
                            System.out.println(" Book number :" + B.getBookNum() + "\t" + " Title :" + B.BookName
                                    + "\t" + " author :" + B.getBookAuthor() + "\t" + " Press. :" + B.getPublisher()
                                    + "\t" + " Publication date :" + B.getPublishTime() + "\t" + " Number of Libraries :" + B.getBookCount()
                                    + "\t" + " pricing :" + B.getPrice());
                            flag = 1;
                        }
                        if (flag == 0) {
    
                            System.out.println(" There is no such book , Please re-enter ");
                        }
                        if (flag == 1) {
    
                            System.out.println("1、 Continue checking  2、 sign out ");
                            int choice = sc.nextInt();
                            if (choice == 1) {
    
                                break;
                            }
                            if (choice == 2) {
    
                                return;
                            }
                        }
                    }
                    break;
                case 3:
                    System.out.println(" Please enter the name of the publisher you are looking for :");
                    String publisher = sc.next();
                    for (int i = 0; i < booklist.size(); i++) {
    
                        BookInfo B = booklist.get(i);
                        if (B.getPublisher().equals(publisher)) {
    

                            System.out.println(" Book number :" + B.getBookNum() + "\t" + " Title :" + B.BookName
                                    + "\t" + " author :" + B.getBookAuthor() + "\t" + " Press. :" + B.getPublisher()
                                    + "\t" + " Publication date :" + B.getPublishTime() + "\t" + " Number of Libraries :" + B.getBookCount()
                                    + "\t" + " pricing :" + B.getPrice());
                            flag = 1;
                        }
                        if (flag == 0) {
    
                            System.out.println(" There is no such book , Please re-enter ");
                        }
                        if (flag == 1) {
    
                            System.out.println("1、 Continue checking  2、 sign out ");
                            int choice = sc.nextInt();
                            if (choice == 1) {
    
                                break;
                            }
                            if (choice == 2) {
    
                                return;
                            }
                        }
                    }
                    break;
                default:
                    System.out.println(" Incorrect input , Please re-enter ");
                    break;
            }
        }
    }

Book information sorting

By book number 、 Book titles are sorted in ascending order .

 static void SortBook(ArrayList<BookInfo> booklist)// Book information sorting 
    {
    
        System.out.println(" Please select sort by ");
        System.out.println("1、 Sort by book number " + "\t" + "2、 Sort by title ");
        Scanner sc = new Scanner(System.in);
        int num1 = sc.nextInt();
        if (num1 == 1) {
    
            Collections.sort(booklist, ((o1, o2) -> o1.getBookNum().compareTo(o2.getBookNum())));
            System.out.println(" Sorting by book number succeeded ");
            System.out.println(" The list of books is :");
            for (int i = 0; i < booklist.size(); i++) {
    
                BookInfo B = booklist.get(i);
                System.out.println(" Book number :" + B.getBookNum() + "\t" + " Title :" + B.BookName
                        + "\t" + " author :" + B.getBookAuthor() + "\t" + " Press. :" + B.getPublisher()
                        + "\t" + " Publication date :" + B.getPublishTime() + "\t" + " Number of Libraries :" + B.getBookCount()
                        + "\t" + " pricing :" + B.getPrice());
            }
            System.out.println(" Please enter 0 Exit sort ");
            if (sc.nextInt() == 0) {
    
                return;
            }
        }
        if (num1 == 2) {
    
            Collections.sort(booklist, ((o1, o2) -> o1.getBookName().compareTo(o2.getBookName())));
            System.out.println(" Sorting by book title succeeded ");
            System.out.println(" The list of books is :");

            for (int i = 0; i < booklist.size(); i++) {
    
                System.out.println(booklist.get(i).toString());
            }
            System.out.println(" Please enter 0 Exit sort ");
            if (sc.nextInt() == 0) {
    
                return;
            }
        }
    }

Modification of book information 、 Delete

Modify and delete books by book number or title .

  public static void ChangeBook(ArrayList<BookInfo> booklist)// Book information modification 
    {
    
        while (true) {
    
            int flag = 1;// Mark whether there is a corresponding book 
            System.out.println(" Please select the modification type ");
            System.out.println("1、 By book number " + "\t" + "2、 By title ");
            Scanner sc = new Scanner(System.in);
            int Num1 = sc.nextInt();
            if (Num1 == 1) {
    
                System.out.println(" Please enter the book number to be queried ");
                String Num2 = sc.next();
                for (int i = 0; i < booklist.size(); i++) {
    

                    BookInfo B = booklist.get(i);
                    if (Num2.equals(booklist.get(i).BookNum)) {
    
                        flag = 0;// Marked with corresponding books 
                        System.out.println(" The original title of the book is " + booklist.get(i).BookName);
                        System.out.println(" Please enter the revised book number 、 Title 、 author 、 Press. 、 Number of Libraries 、 pricing ");
                        B.setBookInfo(sc.next(), sc.next(), sc.next(), sc.next(), sc.next(), sc.nextInt(), sc.nextDouble());
                        System.out.println(" Modification successful ");
                        System.out.println("1、 Continue to modify \t2、 End modification ");
                        int chioce = sc.nextInt();
                        if (chioce == 1) {
    
                            break;
                        } else if (chioce == 2) {
    
                            return;
                        } else {
    
                            System.out.println(" Incorrect input , Continue to modify by default ");
                        }
                    }
                }
                if (flag == 1)
                    System.out.println(" There is no such book , Please re-enter ");
            } else if (Num1 == 2) {
    
                System.out.println(" Please enter the title of the book to be queried ");
                String Bookname = sc.next();
                for (int i = 0; i < booklist.size(); i++) {
    
                    BookInfo B = booklist.get(i);
                    if (Bookname.equals(booklist.get(i).BookName)) {
    
                        flag = 0;
                        System.out.println(" The original title of the book is " + booklist.get(i).BookName);
                        System.out.println(" Please enter the revised book number 、 Title 、 author 、 Press. 、 Number of Libraries 、 pricing ");
                        B.setBookInfo(sc.next(), sc.next(), sc.next(), sc.next(), sc.next(), sc.nextInt(), sc.nextDouble());
                        System.out.println(" Modification successful ");

                        System.out.println("1、 Continue to modify \t2、 End modification ");
                        int chioce = sc.nextInt();
                        if (chioce == 1) {
    
                            break;
                        } else if (chioce == 2) {
    
                            return;
                        } else {
    
                            System.out.println(" Incorrect input , Continue to modify by default ");
                        }
                    }
                }
                if (flag == 1)
                    System.out.println(" There is no such book , Please re-enter ");
            } else {
    
                System.out.println(" Incorrect input , Please re-enter ");
            }

        }
    }

Student

Create a student class

public class ReaderInfo  {
    
    public ReaderInfo(String ID, String readerName, String college, String aClass) {
    
        this.ID = ID;
        ReaderName = readerName;
        College = college;
        Class = aClass;
    }
public void setReader(String ID, String readerName, String college, String aClass)
        {
    
            this.ID = ID;
            ReaderName = readerName;
            College = college;
            Class = aClass;
        }
    public String toString() {
    
        return " Student ID:" + ID + "\t" + "  The student's name :" + ReaderName + "\t" +
                " college :" + College + "\t" + "  class :" + Class ;
    }
    public String ID;  // Student number 
    public String ReaderName; // full name 
    public String College; // college 
    public  String Class; //  Professional class 
}

Student information adding function

Including student ID 、 full name 、 college 、 Professional classes, etc

public   static void AddReader()// Student information added 
    {
    
        Scanner sc = new Scanner(System.in);
        while (true) {
    
            System.out.println(" At present, there is " + readlist.size() + " A reader !");
            System.out.println(" Please enter the student id number 、 full name 、 college 、 Professional class ");
            ReaderInfo R = new ReaderInfo(sc.next(), sc.next(), sc.next(), sc.next());
            readlist.add(R);
            System.out.println(" Student information added successfully ");
            System.out.println("1、 Continue to add \t2、 End adding ");
            int chioce = sc.nextInt();
            if (chioce == 1) {
    
                continue;
            }
            if (chioce == 2) {
    
                break;
            }
        }
    }

Student information inquiry

By student number 、 full name 、 Professional classes, etc

public static void PrintReader()// Student information inquiry 
    {
    
        Scanner sc = new Scanner(System.in);
        OUT1:
        while (true) {
    
            System.out.println(" Enter the student number or name or class of the student to be queried ");
            int flag = 1;
            String Info = sc.next();
            for (int i = 0; i < readlist.size(); i++) {
    
                if (Info.equals(readlist.get(i).ReaderName) || Info.equals(readlist.get(i).ID) || Info.equals(readlist.get(i).Class)) {
    
                    flag = 0;
                    System.out.println(readlist.get(i).toString());
                    System.out.println("1、 Continue query " + "\t" + "2、 The end of the query ");
                    int choice = sc.nextInt();
                    if (choice == 1) {
    
                        break;
                    }
                    if (choice == 2) {
    
                        break OUT1;
                    }
                }
            }
            if (flag == 1) {
    
                System.out.println(" This person... Is not found , Please re-enter ");
            }
        }
    }

Student information ranking

According to the student id 、 Colleges, etc. are sorted in ascending order

public static void SortStu()// Student information ranking 
    {
    
        System.out.println("1、 Sort by student number " + "\t" + "2、 Sort by College ");
        Scanner sc = new Scanner(System.in);
        int choice = sc.nextInt();
        if (choice == 1) {
    
            Collections.sort(readlist, (o1, o2) -> o1.ID.compareTo(o2.ID));
            System.out.println(" Sort success ");
            System.out.println(" Student list :");
            for (int i = 0; i < readlist.size(); i++) {
    
                System.out.println(readlist.get(i).toString());
            }
            System.out.println(" Please enter 0 Exit sort ");
            if (sc.nextInt() == 0) {
    
                return;
            }
        }
        if (choice == 2) {
    
            Collections.sort(readlist, (o1, o2) -> o1.College.compareTo(o2.College));
            System.out.println(" Sort success ");
            System.out.println(" Student list :");
            for (int i = 0; i < readlist.size(); i++) {
    
                System.out.println(readlist.get(i).toString());
            }
            System.out.println(" Please enter 0 Exit sort ");
            if (sc.nextInt() == 0) {
    
                return;
            }
        }
    }

Modification of student information 、 Delete

According to the student id + Name to modify and delete reader information

 public static void ChaReStu()// Modification of student information 、 Delete 
    {
    
        Scanner sc = new Scanner(System.in);
        while (true) {
    
            int flag = 1;// Mark 
            System.out.println(" According to the student id + Name to modify and delete student information ");
            System.out.println(" Please enter student number and student name ");
            String Id = sc.next();
            String StuName = sc.next();
            for (int i = 0; i < readlist.size(); i++) {
    
                if (readlist.get(i).ID.equals(Id) && readlist.get(i).ReaderName.equals(StuName)) {
    
                    flag = 0;
                    System.out.println("1、 Make changes " + "\t" + "2、 To delete ");
                    int chioce = sc.nextInt();
                    if (chioce == 1) {
    
                        ReaderInfo R1 = readlist.get(i);
                        System.out.println(" Please enter new student information ( Student ID、 full name 、 college 、 class )");
                        R1.setReader(sc.next(), sc.next(), sc.next(), sc.next());
                        System.out.println(" Modification successful ");
                        System.out.println("1、 Continue to operate the student information " + "\t" + "2、 End operation ");
                        int Op = sc.nextInt();
                        if (Op == 1) {
    
                            break;
                        }
                        if (Op == 2) {
    
                            return;
                        }
                    }
                    if (chioce == 2) {
    
                        readlist.remove(i);
                        System.out.println(" Delete successful ");
                        System.out.println("1、 Continue to operate the student information " + "\t" + "2、 End operation ");
                        int Op = sc.nextInt();
                        if (Op == 1) {
    
                            break;
                        }
                        if (Op == 2) {
    
                            return;
                        }
                    }
                }
            }

            if (flag == 1) {
    
                System.out.println(" The student information is wrong , Please re-enter ");
            }
        }
    }

Book borrowing

Create information classes for book borrowers

public class BookBorrow  {
    
    public BookBorrow(String ID, String name, String College, String bookNum, String bookName, String lendTime, String legalTime) {
    
        this.ID = ID;
        Name = name;
        this.College = College;
        BookNum = bookNum;
        BookName = bookName;
        LendTime = lendTime;
        LegalTime = legalTime;
    }
    @Override
    public String toString() {
    
        return "ID:" + ID + "\t" + " The student's name :" + Name + "\t" +
                " Book number :" + BookNum + "\t" + " Title :" + BookName +
                "\n" + " Due time :" + LegalTime + '\n' +
                " Return time : " + BorrowTime;
    }

    String ID;  // Student number 
    String Name;// full name 
    String College;
    String BookNum; // Book number 
    String BookName; // Title 
    String LendTime;// Borrowing time 
    String LegalTime;// Due time 
    String BorrowTime = " Borrowing "; // Return time 


    public void setBookReader(String ID, String name)/* Register student information */ {
    
        this.ID = ID;
        Name = name;
    }
// The rest can be constructed directly through the editor ( I won't repeat )
}

With Student number + Book number To borrow

  public static void BorrowBook() // Book borrowing 
    {
    
        Scanner sc = new Scanner(System.in);
        int flag = 0;/* Mark */
        int Br = 0;// Number of book borrowers 
        while (true) {
    
            System.out.println(" Please enter the book number and personal student number of the book you want to borrow to log in :");
            String BookNum = sc.next();
            String Id = sc.next();
            OUT:
            for (int i = 0; i < booklist.size(); i++) {
    
                for (int i1 = 0; i1 < readlist.size(); i1++) {
    
                    if (BookNum.equals(booklist.get(i1).BookNum) && Id.equals(readlist.get(i1).ID)) {
    
                        flag = 1;// The tag finds the corresponding student information and book information 
                        if (booklist.get(i).BookCount >= 1) {
    

                            booklist.get(i).BookCount -= 1;
                            System.out.println(" Please enter your student number 、 full name 、 College and book number of books borrowed 、 Title :");
                            String Id1 = sc.next();
                            String StuName = sc.next();
                            String College = sc.next();
                            String BookId = sc.next();
                            String BookName = sc.next();
                            String LendT = LendTime();
                            String LegT = LealTime();
                            BookBorrow B = new BookBorrow(Id1, StuName, College, BookId, BookName, LendT, LegT);
                            borrowlist.add(B);

                            System.out.println(" Student student id :" + borrowlist.get(Br).ID + "\t" + " full name " + borrowlist.get(Br).Name +
                                    "\t" + " Book number :" + borrowlist.get(Br).BookNum + "\t" + " Title :" + borrowlist.get(Br).BookName);
                            System.out.println(" Borrowing time :" + borrowlist.get(Br).LendTime);
                            System.out.println(" Due time :" + borrowlist.get(Br).LegalTime);
                            System.out.println(" Borrowing succeeded ");
                            System.out.println("1、 Continue to borrow " + "\t" + "2、 Exit the system ");
                            int chioce = sc.nextInt();
                            if (chioce == 1) {
    
                                break OUT;
                            }
                            if (chioce == 2) {
    
                                return;
                            }
                        } else if (booklist.get(i).BookCount < 1) {
    
                            System.out.println(" This book has been completely borrowed , Please reselect ");
                            System.out.println("1、 Continue to borrow " + "\t" + "2、 Exit the system ");
                            int chioce = sc.nextInt();
                            if (chioce == 1) {
    
                                break OUT;
                            }
                            if (chioce == 2) {
    
                                return;
                            }
                        }
                    }
                }
            }
            if (flag == 0) {
    
                System.out.println(" Incorrect input , Please re-enter ");
            }
        }
    }

Book return

With Student number + Book number The way to return books

  public static void BackBook()// Book return 
    {
    
        Scanner sc = new Scanner(System.in);
        int flag = 1;// Mark whether the correct information is found 
        OUT:
        while (true) {
    
            System.out.println(" Please enter the student number and book number :");
            String StuId = sc.next();
            String BookId = sc.next();
            for (int i = 0; i < borrowlist.size(); i++) {
    
                if (StuId.equals(borrowlist.get(i).ID) && BookId.equals(borrowlist.get(i).BookNum)) {
    
                    flag = 0;// Mark to find the correct information 
                    System.out.println(borrowlist.get(i).toString());
                    System.out.println("1、 The return  2、 return ");
                    int choice = sc.nextInt();
                    if (choice == 1) {
    
                        booklist.get(i).BookCount++;
                        String CurrentTime = LendTime();
                        borrowlist.get(i).setBorrowTime(CurrentTime);
                        System.out.println(" Successful return ");
                        System.out.println(borrowlist.get(i).toString());
                        System.out.println("1、 Continue to return  2、 sign out ");
                        int choice1 = sc.nextInt();
                        if (choice1 == 1) {
    
                            break OUT;
                        }
                        if (choice1 == 2) {
    
                            return;
                        }

                    }
                    if (choice == 2) {
    
                        System.out.println("1、 Continue to return  2、 sign out ");
                        int choice1 = sc.nextInt();
                        if (choice1 == 1) {
    
                            break OUT;
                        }
                        if (choice1 == 2) {
    
                            return;
                        }

                    }
                }
            }
            if (flag == 1) {
    
                System.out.println(" Please enter the correct information ");
            }
        }
    }

Book borrowing inquiry

public static void PriBookReader() // Book borrowing inquiry 
    {
    
        Scanner sc = new Scanner(System.in);
        while (true) {
    
            int flag = 0;
            System.out.println("1、 By student number  2、 Search by title  3、 Query by College ");
            int chioce = sc.nextInt();
            switch (chioce) {
    
                case 1:
                    System.out.println(" Please enter the student number to inquire ");
                    String Id = sc.next();
                    for (int i = 0; i < borrowlist.size(); i++) {
    
                        if (Id.equals(borrowlist.get(i).ID)) {
    
                            flag = 1;
                            System.out.println(borrowlist.get(i).toString());
                        }
                    }
                    if (flag == 1) {
    
                        System.out.println("1、 Continue query  2、 sign out ");
                        int chioce1 = sc.nextInt();
                        if (chioce1 == 1) {
    
                            break;
                        }
                        if (chioce1 == 2) {
    
                            return;
                        }
                    }
                    if (flag == 0) {
    
                        System.out.println(" The information is wrong , Please re-enter ");
                    }
                    break;
                case 2:
                    System.out.println(" Please enter the title of the book to be queried :");
                    String BN = sc.next();
                    for (int i = 0; i < borrowlist.size(); i++) {
    
                        if (BN.equals(borrowlist.get(i).BookName)) {
    
                            flag = 1;
                            System.out.println(borrowlist.get(i).toString());
                        }
                    }
                    if (flag == 1) {
    
                        System.out.println("1、 Continue query  2、 sign out ");
                        int chioce1 = sc.nextInt();
                        if (chioce1 == 1) {
    
                            break;
                        }
                        if (chioce1 == 2) {
    
                            return;
                        }
                    }
                    if (flag == 0) {
    
                        System.out.println(" The information is wrong , Please re-enter ");
                    }
                    break;
                case 3:
                    System.out.println(" Please enter the college to be queried ");
                    String College = sc.next();
                    for (int i = 0; i < borrowlist.size(); i++) {
    
                        if (College.equals(borrowlist.get(i).College)) {
    
                            flag = 1;
                            System.out.println(borrowlist.get(i).toString());
                        }
                    }
                    if (flag == 1) {
    
                        System.out.println("1、 Continue query  2、 sign out ");
                        int chioce1 = sc.nextInt();
                        if (chioce1 == 1) {
    
                            break;
                        }
                        if (chioce1 == 2) {
    
                            return;
                        }
                    }
                    if (flag == 0) {
    
                        System.out.println(" The information is wrong , Please re-enter ");
                    }
                    break;
                default:
                    System.out.println(" Incorrect input , Please reselect ");
                    break;
            }
        }
    }

IO flow

Take the storage and reading of book information as an example ( Using character stream )
Deposit in :

   public static void OutBookInformation() throws Exception{
    
        Writer file=null;
        try {
    
            file=new FileWriter("D:\\BookInfo.txt",false);
            for (int i = 0; i < booklist.size(); i++) {
    
                BookInfo c=booklist.get(i);
                file.write(String.valueOf(c));
            }
        } catch (Exception e) {
    
            e.printStackTrace();
        }finally {
    
                file.close();
            }
        }

Read :

 public static void Print() throws Exception{
    
        Reader re=new FileReader("D:\\BookInfo.txt");
        char[] buff=new char[100];
         int len;
        while ((len=re.read(buff))!=-1)
            {
    
                String rs=new String(buff,0,len);
                System.out.print(rs);
            }
        }

Add ( About the acquisition of time )

 public static String LendTime()// Get the current time 
    {
    
        Calendar rightnow = Calendar.getInstance();
        int year = rightnow.get(Calendar.YEAR);
        int month = rightnow.get(Calendar.MONTH) + 1;
        int day = rightnow.get(rightnow.DAY_OF_MONTH);
        int hour = rightnow.get(rightnow.HOUR_OF_DAY);//24 hourly 
        int minute = rightnow.get(rightnow.MINUTE);
        int second = rightnow.get(rightnow.SECOND);
        int millisecond = rightnow.get(rightnow.MILLISECOND);
        String TIME = year + "-" + month + "-" + day + "\t" + hour + ":" + minute+":"+second;
        return TIME;
    }

Other time settings reference current time The modification method of the acquisition of can be modified

原网站

版权声明
本文为[One skim and one cross]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/187/202207060918170230.html