-
Notifications
You must be signed in to change notification settings - Fork 0
/
LibraryManagementSystem.java
224 lines (175 loc) · 5.3 KB
/
LibraryManagementSystem.java
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
import java.util.ArrayList;
import java.util.Scanner;
// Interface for User
interface User {
void login();
void logout();
}
// Superclass for Library Staff
class LibraryStaff implements User {
public void login() {
System.out.println(getClass().getSimpleName() + " logged in");
}
public void logout() {
System.out.println(getClass().getSimpleName() + " logged out");
}
public void viewBooks() {
System.out.println("Viewing books");
}
}
// Admin class extending LibraryStaff
class Admin extends LibraryStaff {
public void addLibrarian() {
System.out.println("Librarian added");
}
public void viewLibrarian() {
System.out.println("Viewing librarians");
}
public void deleteLibrarian() {
System.out.println("Librarian deleted");
}
public void deleteBooks() {
System.out.println("Book deleted");
}
}
// Librarian class extending LibraryStaff
class Librarian extends LibraryStaff {
public void addBooks() {
System.out.println("Books added");
}
public void issueBooks() {
System.out.println("Book issued");
}
public void viewIssuedBooks() {
System.out.println("Viewing issued books");
}
public void returnBooks() {
System.out.println("Book returned");
}
}
// Class for managing books
class BookManager {
private ArrayList<Book> books;
public BookManager() {
this.books = new ArrayList<>();
}
public void addBook(Book book) {
books.add(book);
System.out.println("Book added: " + book.getTitle());
}
public void viewBooks() {
System.out.println("Viewing books");
for (Book book : books) {
System.out.println(book.getTitle() + " by " + book.getAuthor());
}
}
public void deleteBook(Book book) {
books.remove(book);
System.out.println("Book deleted: " + book.getTitle());
}
}
// Class representing a book
class Book {
private String title;
private String author;
private int yearPublished;
public Book(String title, String author, int yearPublished) {
this.title = title;
this.author = author;
this.yearPublished = yearPublished;
}
public String getTitle() {
return title;
}
public String getAuthor() {
return author;
}
public int getYearPublished() {
return yearPublished;
}
}
// Class for managing issued books
class IssueManager {
private ArrayList<IssuedBook> issuedBooks;
public IssueManager() {
this.issuedBooks = new ArrayList<>();
}
public void issueBook(Book book, User user) {
issuedBooks.add(new IssuedBook(book, user));
System.out.println("Book issued to " + user.getClass().getSimpleName());
}
public void viewIssuedBooks() {
System.out.println("Viewing issued books");
for (IssuedBook issuedBook : issuedBooks) {
System.out.println("Book issued to " + issuedBook.getUser().getClass().getSimpleName() +
": " + issuedBook.getBook().getTitle());
}
}
public void returnBook(IssuedBook issuedBook) {
issuedBooks.remove(issuedBook);
System.out.println("Book returned: " + issuedBook.getBook().getTitle());
}
}
// Class representing an issued book
class IssuedBook {
private Book book;
private User user;
public IssuedBook(Book book, User user) {
this.book = book;
this.user = user;
}
public Book getBook() {
return book;
}
public User getUser() {
return user;
}
}
// Class for managing user data stored in CSV file
class UserDataManager {
private String csvFilePath;
public UserDataManager(String csvFilePath) {
this.csvFilePath = csvFilePath;
}
public void loadUserData() {
System.out.println("Loading user data from " + csvFilePath);
}
public void saveUserData() {
System.out.println("Saving user data to " + csvFilePath);
}
}
public class LibraryManagementSystem {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
Admin admin = new Admin();
Librarian librarian = new Librarian();
BookManager bookManager = new BookManager();
IssueManager issueManager = new IssueManager();
UserDataManager userDataManager = new UserDataManager("user_data.csv");
System.out.println("Welcome to Library Management System!");
// Load user data
userDataManager.loadUserData();
// Admin login
admin.login();
// Adding a librarian
admin.addLibrarian();
// View all librarians
admin.viewLibrarian();
// Adding books
bookManager.addBook(new Book("Book1", "Author1", 2000));
bookManager.addBook(new Book("Book2", "Author2", 2005));
// View all books
bookManager.viewBooks();
// Issue a book
librarian.issueBooks();
// View issued books
issueManager.viewIssuedBooks();
// Return a book
issueManager.returnBook(new IssuedBook(new Book("Book1", "Author1", 2000), librarian));
// Admin logout
admin.logout();
// Save user data
userDataManager.saveUserData();
scanner.close();
}
}