///'import java.util.ArrayList;import java.util.Collections;import java.util.List;class Book {private String title;private String author;private String publicationDate;private String storageDate;private boolean borrowed;public Book(String title, String author, String publicationDate, String storageDate) {this.title = title;this.author = author;this.publicationDate = publicationDate;this.storageDate = storageDate;this.borrowed = false;}public String getTitle() {return title;}public String getAuthor() {return author;}public String getPublicationDate() {return publicationDate;}public String getStorageDate() {return storageDate;}public boolean isBorrowed() {return borrowed;}public void setBorrowed(boolean borrowed) {this.borrowed = borrowed;}}class Library {private String name;private String address;private List books;public Library(String name, String address) {this.name = name;this.address = address;this.books = new ArrayList<>();}public void addBook(Book book) {books.add(book);}public List getAllBooks() {return books;}}class BorrowRecord {private Book book;private String borrowDate;private String returnDate;public BorrowRecord(Book book, String borrowDate, String returnDate) {this.book = book;this.borrowDate = borrowDate;this.returnDate = returnDate;}public Book getBook() {return book;}public String getBorrowDate() {return borrowDate;}public String getReturnDate() {return returnDate;}}class Reader {private String name;private List borrowList;public Reader(String name) {this.name = name;this.borrowList = new ArrayList<>();}public String getName() {return name;}public List getBorrowList() {return borrowList;}public void borrowBook(Book book, String borrowDate, String returnDate) {BorrowRecord borrowRecord = new BorrowRecord(book, borrowDate, returnDate);borrowList.add(borrowRecord);book.setBorrowed(true);}public void returnBook(Book book) {for (BorrowRecord record : borrowList) {if (record.getBook().equals(book)) {borrowList.remove(record);book.setBorrowed(false);break;}}}}class LibrarySystem {private Library library;private List readers;private List books;public LibrarySystem() {this.library = null;this.readers = new ArrayList<>();this.books = new ArrayList<>();}public void createLibrary(String name, String address) {library = new Library(name, address);}public void addBook(Book book) {books.add(book);library.addBook(book);}public void registerReader(Reader reader) {readers.add(reader);}public void borrowBook(Reader reader, Book book, String borrowDate, String returnDate) {if (readers.contains(reader) && !book.isBorrowed()) {reader.borrowBook(book, borrowDate, returnDate);} else {System.out.println(/'Invalid reader or book is already borrowed./');}}public void returnBook(Reader reader, Book book) {if (readers.contains(reader) && book.isBorrowed()) {reader.returnBook(book);} else {System.out.println(/'Invalid reader or book is not borrowed./');}}public void printAllBooks() {Collections.sort(books, (b1, b2) -> b1.getStorageDate().compareTo(b2.getStorageDate()));for (Book book : books) {System.out.println(/'Title: /' + book.getTitle());System.out.println(/'Author: /' + book.getAuthor());System.out.println(/'Publication Date: /' + book.getPublicationDate());System.out.println(/'Storage Date: /' + book.getStorageDate());System.out.println(/'Borrowed: /' + (book.isBorrowed() ? /'Yes/' : /'No/'));System.out.println();}}public void printReaderBorrowList(Reader reader) {if (readers.contains(reader)) {List borrowList = reader.getBorrowList();for (BorrowRecord record : borrowList) {Book book = record.getBook();System.out.println(/'Title: /' + book.getTitle());System.out.println(/'Author: /' + book.getAuthor());System.out.println(/'Publication Date: /' + book.getPublicationDate());System.out.println(/'Storage Date: /' + book.getStorageDate());System.out.println(/'Borrow Date: /' + record.getBorrowDate());System.out.println(/'Return Date: /' + record.getReturnDate());System.out.println();}} else {System.out.println(/'Invalid reader./');}}}public class LibraryManagementSystem {public static void main(String[] args) {LibrarySystem librarySystem = new LibrarySystem();librarySystem.createLibrary(/'ABC Library/', /'123 Main St/');Book book1 = new Book(/'Book 1/', /'Author 1/', /'2021-01-01/', /'2021-01-10/');Book book2 = new Book(/'Book 2/', /'Author 2/', /'2021-02-01/', /'2021-02-10/');Book book3 = new Book(/'Book 3/', /'Author 3/', /'2021-03-01/', /'2021-03-10/');librarySystem.addBook(book1);librarySystem.addBook(book2);librarySystem.addBook(book3);Reader reader1 = new Reader(/'Reader 1/');Reader reader2 = new Reader(/'Reader 2/');librarySystem.registerReader(reader1);librarySystem.registerReader(reader2);librarySystem.borrowBook(reader1, book1, /'2021-04-01/', /'2021-04-10/');librarySystem.borrowBook(reader2, book2, /'2021-05-01/', /'2021-05-10/');librarySystem.returnBook(reader1, book1);librarySystem.returnBook(reader2, book2);librarySystem.printAllBooks();librarySystem.printReaderBorrowList(reader1);librarySystem.printReaderBorrowList(reader2);}}///'这个程序模拟了一个简单的图书馆借阅系统,包括创建图书馆、添加书籍、注册读者、借书、还书等功能。可以根据需要进行修改和扩展。///


原文地址: https://www.cveoy.top/t/topic/p525 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录