As a test, in the run method of the anonymous class, you can try to manually add to your library (model object) some lenders and borrowers to check that whether your GUI displays the correct the total number of books borrowed by all users in the library.
时间: 2023-07-02 15:05:29 浏览: 111
Sure, I can definitely try that. Here's an example code snippet to manually add lenders and borrowers to the library:
```
Library library = new Library();
// Add lenders
Lender lender1 = new Lender("John");
Lender lender2 = new Lender("Sarah");
library.addLender(lender1);
library.addLender(lender2);
// Add borrowers
Borrower borrower1 = new Borrower("Mike");
Borrower borrower2 = new Borrower("Emily");
library.addBorrower(borrower1);
library.addBorrower(borrower2);
// Add books to the library
Book book1 = new Book("The Great Gatsby", "F. Scott Fitzgerald", "1234567890");
Book book2 = new Book("To Kill a Mockingbird", "Harper Lee", "0987654321");
library.addBook(book1);
library.addBook(book2);
// Lender John borrows book1 and book2
library.borrowBook(book1, lender1);
library.borrowBook(book2, lender1);
// Lender Sarah borrows book2
library.borrowBook(book2, lender2);
// Borrower Mike borrows book1
library.borrowBook(book1, borrower1);
// Borrower Emily borrows book1 and book2
library.borrowBook(book1, borrower2);
library.borrowBook(book2, borrower2);
// Check the total number of books borrowed by all users
int totalBooksBorrowed = library.getTotalBooksBorrowedByAllUsers();
System.out.println("Total books borrowed: " + totalBooksBorrowed); // Output: Total books borrowed: 5
```
Assuming that the GUI is correctly linked to the library object, it should display the correct total number of books borrowed by all users, which in this case is 5.
阅读全文