Repository navigation
Expand file tree
/
Copy pathLibrarian.java
More file actions
59 lines (49 loc) · 1.95 KB
/
Copy pathLibrarian.java
File metadata and controls
59 lines (49 loc) · 1.95 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
import java.util.List;
public class Librarian extends User {
public Librarian(String username, String password, String name) {
super(username, password, name);
}
@Override
public String getRole() {
return "Librarian";
}
public void addPrintedBook(LibrarySystem library, String title, String author, String genre, String isbn, int pages) {
// Check if ISBN already exists
if (library.getBookByIsbn(isbn) != null) {
System.out.println("ISBN already exists. Book not added.");
return;
}
Book book = new PrintedBook(title, author, genre, isbn, pages);
library.addBook(book);
System.out.println("PrintedBook " + title + " added successfully.");
}
public void addEbook(LibrarySystem library, String title, String author, String genre, String isbn, String format) {
// Check if ISBN already exists
if (library.getBookByIsbn(isbn) != null) {
System.out.println("ISBN already exists. Book not added.");
return;
}
Book book = new Ebook(title, author, genre, isbn, format);
library.addBook(book);
System.out.println("Ebook " + title + " added successfully.");
}
public void removeBook(LibrarySystem library, String isbn) {
boolean removed = library.removeBook(isbn);
if (removed) {
System.out.println("Book with ISBN " + isbn + " removed successfully.");
} else {
System.out.println("Book with ISBN " + isbn + " not found.");
}
}
public void listBooks(LibrarySystem library) {
List<Book> books = library.getAllBooks();
if (books.isEmpty()) {
System.out.println("No books in the library.");
return;
}
System.out.println("All Books:");
for (Book book : books) {
System.out.println(book);
}
}
}