(Unknown Source)
99 | at org.apache.derby.jdbc.InternalDriver.getNewEmbedConnection(Unknown Source)
100 | at org.apache.derby.jdbc.InternalDriver.connect(Unknown Source)
101 | at org.apache.derby.jdbc.InternalDriver.connect(Unknown Source)
102 | at org.apache.derby.jdbc.EmbeddedDriver.connect(Unknown Source)
103 | at org.apache.derby.impl.drda.Database.makeConnection(Unknown Source)
104 | at org.apache.derby.impl.drda.DRDAConnThread.getConnFromDatabaseName(Unknown Source)
105 | at org.apache.derby.impl.drda.DRDAConnThread.verifyUserIdPassword(Unknown Source)
106 | at org.apache.derby.impl.drda.DRDAConnThread.parseSECCHK(Unknown Source)
107 | at org.apache.derby.impl.drda.DRDAConnThread.parseDRDAConnection(Unknown Source)
108 | at org.apache.derby.impl.drda.DRDAConnThread.processCommands(Unknown Source)
109 | at org.apache.derby.impl.drda.DRDAConnThread.run(Unknown Source)
110 | ============= end nested exception, level (1) ===========
111 | Cleanup action completed
112 | Mon Jul 02 20:43:38 PKT 2018 Thread[DRDAConnThread_2,5,main] (DATABASE = Library Management System), (DRDAID = {2}), Connection authentication failure occurred. Reason: Invalid authentication..
113 | ----------------------------------------------------------------
114 | Mon Jul 02 20:44:22 PKT 2018: Shutting down Derby engine
115 | ----------------------------------------------------------------
116 | Mon Jul 02 20:44:22 PKT 2018:
117 | Shutting down instance a816c00e-0164-5ba9-a8a5-00007b18d1a8 on database directory D:\FAST\5th Semester (Fall 2017)\Object Oriented Analysis and Design\Assignments\Library Management System\Library Management System with class loader sun.misc.Launcher$AppClassLoader@1d44bcfa
118 | ----------------------------------------------------------------
119 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # 📚 Library Management System -Java
2 |
3 |
4 |
5 | [](#)
6 | [](https://www.github.com/harismuneer/Library-Management-System-JAVA/fork)
7 | [](https://www.github.com/harismuneer/Library-Management-System-JAVA/issues)
8 | [](#)
9 |
10 |
11 | A Library Management System made using the concepts of Object Oriented Analysis and Design. Minimal Code is written in the GUI and the entities are decoupled as well. The interface is console based. This project was designed during the course "Object Oriented Analysis and Design CS309".
12 |
13 | The **Class Diagram** of the project is also provided along with the **Database Schema** file. The class diagram file can be opened using [Star UML](http://staruml.io/).
14 |
15 | ## Class Diagram
16 | 
17 |
18 | **Note**: After Refactoring, new Class "HoldRequestOperations" is added to the above structure which lies in between the HoldRequest class and Book class.
19 | This class removes the bidirectional dependency between HoldRequest and Book. More details mentioned [here](https://github.com/OSSpk/Library-Management-System-JAVA/issues/9)
20 |
21 | ## Interface
22 |
23 |
24 |
25 |
26 |
27 | ## Actors:
28 | The actors include the following:
29 | * Librarian
30 | * Checkout Clerk
31 | * Borrower
32 | * Administrator
33 |
34 | ## Use Cases:
35 | After determining the actors, the second step in use case analysis is to determine the tasks that each actor will need to do with the system. Each task is called a use case because it represents one particular way the system will be used.
36 |
37 | **In other words, only those use cases are listed that actors will need to do when they are using the system to solve the customer’s problem.**
38 |
39 | ### Borrower:
40 | * ❏ Search for items by title.
41 | * ❏ ... by author.
42 | * ❏ ... by subject.
43 | * ❏ Place a book on hold if it is on loan to somebody else.
44 | * ❏ Check the borrower’s personal information and list of books currently
45 | borrowed.
46 |
47 | ### Checkout Clerk:
48 | * ❏ All the Borrower use cases, plus
49 | * ❏ Check out an item for a borrower.
50 | * ❏ Check in an item that has been returned.
51 | * ❏ Renew an item.
52 | * ❏ Record that a fine has been paid.
53 | * ❏ Add a new borrower.
54 | * ❏ Update a borrower’s personal information (address, telephone number etc.).
55 |
56 | ### Librarian:
57 | * ❏ All of the Borrower and Checkout Clerk use cases, plus
58 | * ❏ Add a new item to the collection.
59 | * ❏ Delete an item from the collection.
60 | * ❏ Change the information the system has recorded about an item.
61 |
62 | ### Administrator:
63 | * ❏ Add Clerk.
64 | * ❏ Add Librarian.
65 | * ❏ View Issued Books History.
66 | * ❏ View All Books in Library.
67 |
68 |
69 | ## How to Run
70 | 1- Install these:
71 | * [Java SE Development Kit 8 (JDK 8)](http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html)
72 | * After installing JDK 8, install [NetBeans IDE](https://netbeans.org/downloads/)
73 |
74 | 2- Open NetBeans IDE. Click on File -> Open Project and browse to the downloaded folder named "Project" and select it. It will load the NetBeans project.
75 |
76 | 3- Now everything is setup except the Java DB (Derby) Database of NetBeans. So, follow these steps to setup the database:
77 |
78 | **Step 1:** In the Netbeans Window, there is a tab named "Services" on the left. Select it. Then right click on JavaDB > Properties and change database location to "Database" folder downloaded with this repository (its placed besides the "Project" folder).
79 |
80 | 
81 |
82 | **Step 2:** After that a database named LMS will show up under JavaDB tab. Now Right Click Databases > New Connection and select Java DB Network and click Next.
83 |
84 | 
85 |
86 | **Step 3:** Provide the following database crendentials in the next popup and click Next.
87 | ```
88 | Host: localhost
89 | Port: 1527
90 | Database: LMS
91 | User Name: haris
92 | Password: 123
93 | ```
94 | 
95 |
96 | **Step 4:**
97 | Now just click Next for the rest of the windows. After all this the database connection is made. Make sure that you connect with the database before running the project by right clicking on the connection and selecting connect. Now you are ready to run the project!
98 |
99 | 
100 |
101 | ## Note
102 | The password for Administrative Functions is *lib*. The admin adds new clerks and librarian, then they both do the rest of the functions.
103 |
104 |
105 |
106 | ## Authors 👋
107 |
108 | You can get in touch with us on our LinkedIn Profiles:
109 |
110 | #### Haris Muneer
111 |
112 | [](https://www.linkedin.com/in/harismuneer)
113 |
114 | You can also follow my GitHub Profile to stay updated about my latest projects: [](https://github.com/harismuneer)
115 |
116 | #### Maham Amjad
117 |
118 | [](https://www.linkedin.com/in/maham-amjad-40796b177/)
119 |
120 | You can also follow my GitHub Profile to stay updated about my latest projects: [](https://github.com/MahamAmjad)
121 |
122 | If you liked the repo then kindly support it by giving it a star ⭐ and share in your circles so more people can benefit from the effort.
123 |
124 | ## Contributions Welcome
125 | [](https://www.github.com/harismuneer/Library-Management-System-JAVA/issues)
126 |
127 | If you find any bugs, have suggestions, or face issues:
128 |
129 | - Open an Issue in the Issues Tab to discuss them.
130 | - Submit a Pull Request to propose fixes or improvements.
131 | - Review Pull Requests from other contributors to help maintain the project's quality and progress.
132 |
133 | This project thrives on community collaboration! Members are encouraged to take the initiative, support one another, and actively engage in all aspects of the project. Whether it’s debugging, fixing issues, or brainstorming new ideas, your contributions are what keep this project moving forward.
134 |
135 | With modern AI tools like ChatGPT, solving challenges and contributing effectively is easier than ever. Let’s work together to make this project the best it can be! 🚀
136 |
137 | ## License
138 | [](../master/LICENSE)
139 |
140 | Copyright (c) 2018-present, harismuneer, MahamAmjad
141 |
142 |
143 |
144 |
145 |
146 |
147 | Hey there, I'm Haris Muneer 👨🏻💻
148 |
149 |
150 |
151 |
152 |
153 |
154 |
155 |
156 | - 🛠️ Product Builder: Agile Product Manager with 5+ years of hands-on experience delivering SaaS solutions across sales, recruiting, AI, social media, and public sector domains. Background in Computer Science, with a proven track record of scaling products from inception to $XXM+ ARR, launching 3 top-ranking tools on Product Hunt, and developing solutions adopted by 250+ B2B clients in 40+ countries.
157 |
158 | - 🌟 Open Source Advocate: Passionate about making technology accessible, I’ve developed and open-sourced several software projects for web, mobile, desktop, and AI on my GitHub profile. These projects have been used by thousands of learners worldwide to enhance their skills and knowledge.
159 |
160 | - 📫 How to Reach Me: To learn more about my skills and work, visit my LinkedIn profile. For collaboration or inquiries, feel free to reach out via email.
161 |
162 |
163 |
164 | 🤝 Follow my journey
165 |
166 |
167 |
168 |
169 |
170 |
171 |
172 |
173 |
174 |
175 |
176 |
177 |
178 |
179 |
180 |
--------------------------------------------------------------------------------
/Project/src/LMS/Book.java:
--------------------------------------------------------------------------------
1 |
2 | package LMS;
3 |
4 | import java.io.*;
5 | import java.time.temporal.ChronoUnit;
6 | import java.util.*;
7 |
8 | public class Book {
9 |
10 | private int bookID; // ID given by a library to a book to make it distinguishable from other books
11 | private String title; // Title of a book
12 | private String subject; // Subject to which a book is related!
13 | private String author; // Author of book!
14 | private boolean isIssued; // this will be true if the book is currently issued to some borrower.
15 | private HoldRequestOperations holdRequestsOperations =new HoldRequestOperations();
16 | static int currentIdNumber = 0; //This will be unique for every book, since it will be incremented when everytime
17 | //when a book is created
18 |
19 |
20 | public Book(int id,String t, String s, String a, boolean issued) // Parameterise cons.
21 | {
22 | currentIdNumber++;
23 | if(id==-1)
24 | {
25 | bookID = currentIdNumber;
26 | }
27 | else
28 | bookID=id;
29 |
30 | title = t;
31 | subject = s;
32 | author = a;
33 | isIssued = issued;
34 |
35 | }
36 |
37 |
38 | // printing all hold req on a book.
39 | public void printHoldRequests()
40 | {
41 | if (!holdRequestsOperations.holdRequests.isEmpty())
42 | {
43 | System.out.println("\nHold Requests are: ");
44 |
45 | System.out.println("---------------------------------------------------------------------------------------------------------------------------------------");
46 | System.out.println("No.\t\tBook's Title\t\t\tBorrower's Name\t\t\tRequest Date");
47 | System.out.println("---------------------------------------------------------------------------------------------------------------------------------------");
48 |
49 | for (int i = 0; i < holdRequestsOperations.holdRequests.size(); i++)
50 | {
51 | System.out.print(i + "-" + "\t\t");
52 | holdRequestsOperations.holdRequests.get(i).print();
53 | }
54 | }
55 | else
56 | System.out.println("\nNo Hold Requests.");
57 | }
58 |
59 | // printing book's Info
60 | public void printInfo()
61 | {
62 | System.out.println(title + "\t\t\t" + author + "\t\t\t" + subject);
63 | }
64 |
65 | // changign Info of a Book
66 | public void changeBookInfo() throws IOException
67 | {
68 | Scanner scanner = new Scanner(System.in);
69 | String input;
70 |
71 | BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
72 |
73 | System.out.println("\nUpdate Author? (y/n)");
74 | input = scanner.next();
75 |
76 | if(input.equals("y"))
77 | {
78 | System.out.println("\nEnter new Author: ");
79 | author = reader.readLine();
80 | }
81 |
82 | System.out.println("\nUpdate Subject? (y/n)");
83 | input = scanner.next();
84 |
85 | if(input.equals("y"))
86 | {
87 | System.out.println("\nEnter new Subject: ");
88 | subject = reader.readLine();
89 | }
90 |
91 | System.out.println("\nUpdate Title? (y/n)");
92 | input = scanner.next();
93 |
94 | if(input.equals("y"))
95 | {
96 | System.out.println("\nEnter new Title: ");
97 | title = reader.readLine();
98 | }
99 |
100 | System.out.println("\nBook is successfully updated.");
101 |
102 | }
103 |
104 | /*------------Getter FUNCs.---------*/
105 |
106 | public String getTitle()
107 | {
108 | return title;
109 | }
110 |
111 | public String getSubject()
112 | {
113 | return subject;
114 | }
115 |
116 | public String getAuthor()
117 | {
118 | return author;
119 | }
120 |
121 | public boolean getIssuedStatus()
122 | {
123 | return isIssued;
124 | }
125 |
126 | public void setIssuedStatus(boolean s)
127 | {
128 | isIssued = s;
129 | }
130 |
131 | public int getID()
132 | {
133 | return bookID;
134 | }
135 |
136 | public ArrayList getHoldRequests()
137 | {
138 | return holdRequestsOperations.holdRequests;
139 | }
140 | /*-----------------------------------*/
141 |
142 | // Setter Static Func.
143 | public static void setIDCount(int n)
144 | {
145 | currentIdNumber = n;
146 | }
147 |
148 |
149 |
150 |
151 | //-------------------------------------------------------------------//
152 |
153 | // Placing book on Hold
154 | public void placeBookOnHold(Borrower bor)
155 | {
156 | HoldRequest hr = new HoldRequest(bor,this, new Date());
157 |
158 | holdRequestsOperations.addHoldRequest(hr); //Add this hold request to holdRequests queue of this book
159 | bor.addHoldRequest(hr); //Add this hold request to that particular borrower's class as well
160 |
161 | System.out.println("\nThe book " + title + " has been successfully placed on hold by borrower " + bor.getName() + ".\n");
162 | }
163 |
164 |
165 |
166 |
167 | // Request for Holding a Book
168 | public void makeHoldRequest(Borrower borrower)
169 | {
170 | boolean makeRequest = true;
171 |
172 | //If that borrower has already borrowed that particular book. Then he isn't allowed to make request for that book. He will have to renew the issued book in order to extend the return deadline.
173 | for(int i=0;i hRequests = holdRequestsOperations.holdRequests;
218 |
219 | for (int i = 0; i < hRequests.size(); i++)
220 | {
221 | HoldRequest hr = hRequests.get(i);
222 |
223 | //Remove that hold request which has expired
224 | long days = ChronoUnit.DAYS.between(today.toInstant(), hr.getRequestDate().toInstant());
225 | days = 0-days;
226 |
227 | if(days>Library.getInstance().getHoldRequestExpiry())
228 | {
229 | holdRequestsOperations.removeHoldRequest();
230 | hr.getBorrower().removeHoldRequest(hr);
231 | }
232 | }
233 |
234 | if (isIssued)
235 | {
236 | System.out.println("\nThe book " + title + " is already issued.");
237 | System.out.println("Would you like to place the book on hold? (y/n)");
238 |
239 | Scanner sc = new Scanner(System.in);
240 | String choice = sc.next();
241 |
242 | if (choice.equals("y"))
243 | {
244 | makeHoldRequest(borrower);
245 | }
246 | }
247 |
248 | else
249 | {
250 | if (!holdRequestsOperations.holdRequests.isEmpty())
251 | {
252 | boolean hasRequest = false;
253 |
254 | for (int i = 0; i < holdRequestsOperations.holdRequests.size() && !hasRequest;i++)
255 | {
256 | if (holdRequestsOperations.holdRequests.get(i).getBorrower() == borrower)
257 | hasRequest = true;
258 |
259 | }
260 |
261 | if (hasRequest)
262 | {
263 | //If this particular borrower has the earliest request for this book
264 | if (holdRequestsOperations.holdRequests.get(0).getBorrower() == borrower)
265 | serviceHoldRequest(holdRequestsOperations.holdRequests.get(0));
266 |
267 | else
268 | {
269 | System.out.println("\nSorry some other users have requested for this book earlier than you. So you have to wait until their hold requests are processed.");
270 | return;
271 | }
272 | }
273 | else
274 | {
275 | System.out.println("\nSome users have already placed this book on request and you haven't, so the book can't be issued to you.");
276 |
277 | System.out.println("Would you like to place the book on hold? (y/n)");
278 |
279 | Scanner sc = new Scanner(System.in);
280 | String choice = sc.next();
281 |
282 | if (choice.equals("y"))
283 | {
284 | makeHoldRequest(borrower);
285 | }
286 |
287 | return;
288 | }
289 | }
290 |
291 | //If there are no hold requests for this book, then simply issue the book.
292 | setIssuedStatus(true);
293 |
294 | Loan iHistory = new Loan(borrower,this,staff,null,new Date(),null,false);
295 |
296 | Library.getInstance().addLoan(iHistory);
297 | borrower.addBorrowedBook(iHistory);
298 |
299 | System.out.println("\nThe book " + title + " is successfully issued to " + borrower.getName() + ".");
300 | System.out.println("\nIssued by: " + staff.getName());
301 | }
302 | }
303 |
304 |
305 | // Returning a Book
306 | public void returnBook(Borrower borrower, Loan l, Staff staff)
307 | {
308 | l.getBook().setIssuedStatus(false);
309 | l.setReturnedDate(new Date());
310 | l.setReceiver(staff);
311 |
312 | borrower.removeBorrowedBook(l);
313 |
314 | l.payFine();
315 |
316 | System.out.println("\nThe book " + l.getBook().getTitle() + " is successfully returned by " + borrower.getName() + ".");
317 | System.out.println("\nReceived by: " + staff.getName());
318 | }
319 |
320 | } // Book Class Closed
--------------------------------------------------------------------------------
/Project/src/LMS/Main.java:
--------------------------------------------------------------------------------
1 |
2 | package LMS;
3 |
4 | // Including Header Files.
5 | import java.io.*;
6 | import java.util.*;
7 | import java.sql.*;
8 |
9 | public class Main
10 | {
11 | // Clearing Required Area of Screen
12 | public static void clrscr()
13 | {
14 | for (int i = 0; i < 20; i++)
15 | System.out.println();
16 | }
17 |
18 | // Asking for Input as Choice
19 | public static int takeInput(int min, int max)
20 | {
21 | String choice;
22 | Scanner input = new Scanner(System.in);
23 |
24 | while(true)
25 | {
26 | System.out.println("\nEnter Choice: ");
27 |
28 | choice = input.next();
29 |
30 | if((!choice.matches(".*[a-zA-Z]+.*")) && (Integer.parseInt(choice) > min && Integer.parseInt(choice) < max))
31 | {
32 | return Integer.parseInt(choice);
33 | }
34 |
35 | else
36 | System.out.println("\nInvalid Input.");
37 | }
38 |
39 | }
40 |
41 | // Functionalities of all Persons
42 | public static void allFunctionalities(Person person, int choice) throws IOException
43 | {
44 | Library lib = Library.getInstance();
45 |
46 | Scanner scanner = new Scanner(System.in);
47 | int input = 0;
48 |
49 | //Search Book
50 | if (choice == 1)
51 | {
52 | lib.searchForBooks();
53 | }
54 |
55 | //Do Hold Request
56 | else if (choice == 2)
57 | {
58 | ArrayList books = lib.searchForBooks();
59 |
60 | if (books != null)
61 | {
62 | input = takeInput(-1,books.size());
63 |
64 | Book b = books.get(input);
65 |
66 | if("Clerk".equals(person.getClass().getSimpleName()) || "Librarian".equals(person.getClass().getSimpleName()))
67 | {
68 | Borrower bor = lib.findBorrower();
69 |
70 | if (bor != null)
71 | b.makeHoldRequest(bor);
72 | }
73 | else
74 | b.makeHoldRequest((Borrower)person);
75 | }
76 | }
77 |
78 | //View borrower's personal information
79 | else if (choice == 3)
80 | {
81 | if("Clerk".equals(person.getClass().getSimpleName()) || "Librarian".equals(person.getClass().getSimpleName()))
82 | {
83 | Borrower bor = lib.findBorrower();
84 |
85 | if(bor!=null)
86 | bor.printInfo();
87 | }
88 | else
89 | person.printInfo();
90 | }
91 |
92 | //Compute Fine of a Borrower
93 | else if (choice == 4)
94 | {
95 | if("Clerk".equals(person.getClass().getSimpleName()) || "Librarian".equals(person.getClass().getSimpleName()))
96 | {
97 | Borrower bor = lib.findBorrower();
98 |
99 | if(bor!=null)
100 | {
101 | double totalFine = lib.computeFine2(bor);
102 | System.out.println("\nYour Total Fine is : Rs " + totalFine );
103 | }
104 | }
105 | else
106 | {
107 | double totalFine = lib.computeFine2((Borrower)person);
108 | System.out.println("\nYour Total Fine is : Rs " + totalFine );
109 | }
110 | }
111 |
112 | //Check hold request queue of a book
113 | else if (choice == 5)
114 | {
115 | ArrayList books = lib.searchForBooks();
116 |
117 | if (books != null)
118 | {
119 | input = takeInput(-1,books.size());
120 | books.get(input).printHoldRequests();
121 | }
122 | }
123 |
124 | //Issue a Book
125 | else if (choice == 6)
126 | {
127 | ArrayList books = lib.searchForBooks();
128 |
129 | if (books != null)
130 | {
131 | input = takeInput(-1,books.size());
132 | Book b = books.get(input);
133 |
134 | Borrower bor = lib.findBorrower();
135 |
136 | if(bor!=null)
137 | {
138 | b.issueBook(bor, (Staff)person);
139 | }
140 | }
141 | }
142 |
143 | //Return a Book
144 | else if (choice == 7)
145 | {
146 | Borrower bor = lib.findBorrower();
147 |
148 | if(bor!=null)
149 | {
150 | bor.printBorrowedBooks();
151 | ArrayList loans = bor.getBorrowedBooks();
152 |
153 | if (!loans.isEmpty())
154 | {
155 | input = takeInput(-1,loans.size());
156 | Loan l = loans.get(input);
157 |
158 | l.getBook().returnBook(bor, l, (Staff)person);
159 | }
160 | else
161 | System.out.println("\nThis borrower " + bor.getName() + " has no book to return.");
162 | }
163 | }
164 |
165 | //Renew a Book
166 | else if (choice == 8)
167 | {
168 | Borrower bor = lib.findBorrower();
169 |
170 | if(bor!=null)
171 | {
172 | bor.printBorrowedBooks();
173 | ArrayList loans = bor.getBorrowedBooks();
174 |
175 | if (!loans.isEmpty())
176 | {
177 | input = takeInput(-1,loans.size());
178 |
179 | loans.get(input).renewIssuedBook(new java.util.Date());
180 | }
181 | else
182 | System.out.println("\nThis borrower " + bor.getName() + " has no issued book which can be renewed.");
183 | }
184 | }
185 |
186 | //Add new Borrower
187 | else if (choice == 9)
188 | {
189 | lib.createPerson('b');
190 | }
191 |
192 | //Update Borrower's Personal Info
193 | else if (choice == 10)
194 | {
195 | Borrower bor = lib.findBorrower();
196 |
197 | if(bor != null)
198 | bor.updateBorrowerInfo();
199 | }
200 |
201 | //Add new Book
202 | else if (choice == 11)
203 | {
204 | BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
205 |
206 | System.out.println("\nEnter Title:");
207 | String title = reader.readLine();
208 |
209 | System.out.println("\nEnter Subject:");
210 | String subject = reader.readLine();
211 |
212 | System.out.println("\nEnter Author:");
213 | String author = reader.readLine();
214 |
215 | lib.createBook(title, subject, author);
216 | }
217 |
218 | //Remove a Book
219 | else if (choice == 12)
220 | {
221 | ArrayList books = lib.searchForBooks();
222 |
223 | if (books != null)
224 | {
225 | input = takeInput(-1,books.size());
226 |
227 | lib.removeBookfromLibrary(books.get(input));
228 | }
229 | }
230 |
231 | //Change a Book's Info
232 | else if (choice == 13)
233 | {
234 | ArrayList books = lib.searchForBooks();
235 |
236 | if (books!=null)
237 | {
238 | input = takeInput(-1,books.size());
239 |
240 | books.get(input).changeBookInfo();
241 | }
242 | }
243 |
244 | //View clerk's personal information
245 | else if (choice == 14)
246 | {
247 | Clerk clerk = lib.findClerk();
248 |
249 | if(clerk!=null)
250 | clerk.printInfo();
251 | }
252 |
253 | // Functionality Performed.
254 | System.out.println("\nPress any key to continue..\n");
255 | scanner.next();
256 | }
257 |
258 |
259 |
260 |
261 |
262 |
263 | /*-------------------------------------MAIN---------------------------------------------------*/
264 |
265 | public static void main(String[] args)
266 | {
267 | Scanner admin = new Scanner(System.in);
268 |
269 | //-------------------INTERFACE---------------------------//
270 |
271 | Library lib = Library.getInstance();
272 |
273 | // Setting some by default information like name of library ,fine, deadline and limit of hold request
274 | lib.setFine(20);
275 | lib.setRequestExpiry(7);
276 | lib.setReturnDeadline(5);
277 | lib.setName("FAST Library");
278 |
279 | // Making connection with Database.
280 | Connection con = lib.makeConnection();
281 |
282 | if (con == null) // Oops can't connnect !
283 | {
284 | System.out.println("\nError connecting to Database. Exiting.");
285 | return;
286 | }
287 |
288 | try {
289 |
290 | lib.populateLibrary(con); // Populating Library with all Records
291 |
292 | boolean stop = false;
293 | while(!stop)
294 | {
295 | clrscr();
296 |
297 | // FRONT END //
298 | System.out.println("--------------------------------------------------------");
299 | System.out.println("\tWelcome to Library Management System");
300 | System.out.println("--------------------------------------------------------");
301 |
302 | System.out.println("Following Functionalities are available: \n");
303 | System.out.println("1- Login");
304 | System.out.println("2- Exit");
305 | System.out.println("3- Admininstrative Functions"); // Administration has access only
306 |
307 | System.out.println("-----------------------------------------\n");
308 |
309 | int choice = 0;
310 |
311 | choice = takeInput(0,4);
312 |
313 | if (choice == 3)
314 | {
315 | System.out.println("\nEnter Password: ");
316 | String aPass = admin.next();
317 |
318 | if(aPass.equals("lib"))
319 | {
320 | while (true) // Way to Admin Portal
321 | {
322 | clrscr();
323 |
324 | System.out.println("--------------------------------------------------------");
325 | System.out.println("\tWelcome to Admin's Portal");
326 | System.out.println("--------------------------------------------------------");
327 | System.out.println("Following Functionalities are available: \n");
328 |
329 | System.out.println("1- Add Clerk");
330 | System.out.println("2- Add Librarian");
331 | System.out.println("3- View Issued Books History");
332 | System.out.println("4- View All Books in Library");
333 | System.out.println("5- Logout");
334 |
335 | System.out.println("---------------------------------------------");
336 |
337 | choice = takeInput(0,6);
338 |
339 | if (choice == 5)
340 | break;
341 |
342 | if (choice == 1)
343 | lib.createPerson('c');
344 | else if (choice == 2)
345 | lib.createPerson('l');
346 |
347 | else if (choice == 3)
348 | lib.viewHistory();
349 |
350 | else if (choice == 4)
351 | lib.viewAllBooks();
352 |
353 | System.out.println("\nPress any key to continue..\n");
354 | admin.next();
355 | }
356 | }
357 | else
358 | System.out.println("\nSorry! Wrong Password.");
359 | }
360 |
361 | else if (choice == 1)
362 | {
363 | Person person = lib.login();
364 |
365 | if (person == null){}
366 |
367 | else if (person.getClass().getSimpleName().equals("Borrower"))
368 | {
369 | while (true) // Way to Borrower's Portal
370 | {
371 | clrscr();
372 |
373 | System.out.println("--------------------------------------------------------");
374 | System.out.println("\tWelcome to Borrower's Portal");
375 | System.out.println("--------------------------------------------------------");
376 | System.out.println("Following Functionalities are available: \n");
377 | System.out.println("1- Search a Book");
378 | System.out.println("2- Place a Book on hold");
379 | System.out.println("3- Check Personal Info of Borrower");
380 | System.out.println("4- Check Total Fine of Borrower");
381 | System.out.println("5- Check Hold Requests Queue of a Book");
382 | System.out.println("6- Logout");
383 | System.out.println("--------------------------------------------------------");
384 |
385 | choice = takeInput(0,7);
386 |
387 | if (choice == 6)
388 | break;
389 |
390 | allFunctionalities(person,choice);
391 | }
392 | }
393 |
394 | else if (person.getClass().getSimpleName().equals("Clerk"))
395 | {
396 | while(true) // Way to Clerk's Portal
397 | {
398 | clrscr();
399 |
400 | System.out.println("--------------------------------------------------------");
401 | System.out.println("\tWelcome to Clerk's Portal");
402 | System.out.println("--------------------------------------------------------");
403 | System.out.println("Following Functionalities are available: \n");
404 | System.out.println("1- Search a Book");
405 | System.out.println("2- Place a Book on hold");
406 | System.out.println("3- Check Personal Info of Borrower");
407 | System.out.println("4- Check Total Fine of Borrower");
408 | System.out.println("5- Check Hold Requests Queue of a Book");
409 | System.out.println("6- Check out a Book");
410 | System.out.println("7- Check in a Book");
411 | System.out.println("8- Renew a Book");
412 | System.out.println("9- Add a new Borrower");
413 | System.out.println("10- Update a Borrower's Info");
414 | System.out.println("11- Logout");
415 | System.out.println("--------------------------------------------------------");
416 |
417 | choice = takeInput(0,12);
418 |
419 | if (choice == 11)
420 | break;
421 |
422 | allFunctionalities(person,choice);
423 | }
424 | }
425 |
426 | else if (person.getClass().getSimpleName().equals("Librarian"))
427 | {
428 | while(true) // Way to Librarian Portal
429 | {
430 | clrscr();
431 |
432 | System.out.println("--------------------------------------------------------");
433 | System.out.println("\tWelcome to Librarian's Portal");
434 | System.out.println("--------------------------------------------------------");
435 | System.out.println("Following Functionalities are available: \n");
436 | System.out.println("1- Search a Book");
437 | System.out.println("2- Place a Book on hold");
438 | System.out.println("3- Check Personal Info of Borrower");
439 | System.out.println("4- Check Total Fine of Borrower");
440 | System.out.println("5- Check Hold Requests Queue of a Book");
441 | System.out.println("6- Check out a Book");
442 | System.out.println("7- Check in a Book");
443 | System.out.println("8- Renew a Book");
444 | System.out.println("9- Add a new Borrower");
445 | System.out.println("10- Update a Borrower's Info");
446 | System.out.println("11- Add new Book");
447 | System.out.println("12- Remove a Book");
448 | System.out.println("13- Change a Book's Info");
449 | System.out.println("14- Check Personal Info of Clerk");
450 | System.out.println("15- Logout");
451 | System.out.println("--------------------------------------------------------");
452 |
453 | choice = takeInput(0,16);
454 |
455 | if (choice == 15)
456 | break;
457 |
458 | allFunctionalities(person,choice);
459 | }
460 | }
461 |
462 | }
463 |
464 | else
465 | stop = true;
466 |
467 | System.out.println("\nPress any key to continue..\n");
468 | Scanner scanner = new Scanner(System.in);
469 | scanner.next();
470 | }
471 |
472 | //Loading back all the records in database
473 | lib.fillItBack(con);
474 | }
475 | catch(Exception e)
476 | {
477 | System.out.println("\nExiting...\n");
478 | } // System Closed!
479 |
480 | } // Main Closed
481 |
482 | } // Class closed.
483 |
484 |
--------------------------------------------------------------------------------
/Project/src/LMS/Library.java:
--------------------------------------------------------------------------------
1 |
2 | package LMS;
3 |
4 |
5 | // Including Header Files.
6 | import java.io.*;
7 | import java.sql.Connection;
8 | import java.sql.DriverManager;
9 | import java.sql.PreparedStatement;
10 | import java.sql.ResultSet;
11 | import java.sql.SQLException;
12 | import java.sql.SQLIntegrityConstraintViolationException;
13 | import java.sql.Statement;
14 | import java.sql.Types;
15 | import java.util.*;
16 | import java.util.logging.Level;
17 | import java.util.logging.Logger;
18 |
19 |
20 | public class Library {
21 |
22 | private String name; // name of library
23 | public static Librarian librarian; // object of Librarian (only one)
24 | public static ArrayList persons; // all clerks and borrowers
25 | private ArrayList booksInLibrary; // all books in library are here!
26 |
27 | private ArrayList loans; // history of all books which have been issued
28 |
29 | public int book_return_deadline; //return deadline after which fine will be generated each day
30 | public double per_day_fine;
31 |
32 | public int hold_request_expiry; //number of days after which a hold request will expire
33 | //Created object of the hold request operations
34 | private HoldRequestOperations holdRequestsOperations =new HoldRequestOperations();
35 |
36 |
37 | /*----Following Singleton Design Pattern (Lazy Instantiation)------------*/
38 | private static Library obj;
39 |
40 | public static Library getInstance()
41 | {
42 | if(obj==null)
43 | {
44 | obj = new Library();
45 | }
46 |
47 | return obj;
48 | }
49 | /*---------------------------------------------------------------------*/
50 |
51 | private Library() // default cons.
52 | {
53 | name = null;
54 | librarian = null;
55 | persons = new ArrayList();
56 |
57 | booksInLibrary = new ArrayList();
58 | loans = new ArrayList();
59 | }
60 |
61 |
62 | /*------------Setter FUNCs.------------*/
63 |
64 | public void setReturnDeadline(int deadline)
65 | {
66 | book_return_deadline = deadline;
67 | }
68 |
69 | public void setFine(double perDayFine)
70 | {
71 | per_day_fine = perDayFine;
72 | }
73 |
74 | public void setRequestExpiry(int hrExpiry)
75 | {
76 | hold_request_expiry = hrExpiry;
77 | }
78 | /*--------------------------------------*/
79 |
80 |
81 |
82 | // Setter Func.
83 | public void setName(String n)
84 | {
85 | name = n;
86 | }
87 |
88 | /*-----------Getter FUNCs.------------*/
89 |
90 | public int getHoldRequestExpiry()
91 | {
92 | return hold_request_expiry;
93 | }
94 |
95 | public ArrayList getPersons()
96 | {
97 | return persons;
98 | }
99 |
100 | public Librarian getLibrarian()
101 | {
102 | return librarian;
103 | }
104 |
105 | public String getLibraryName()
106 | {
107 | return name;
108 | }
109 |
110 | public ArrayList getBooks()
111 | {
112 | return booksInLibrary;
113 | }
114 |
115 | /*---------------------------------------*/
116 |
117 | /*-----Adding other People in Library----*/
118 |
119 | public void addClerk(Clerk c)
120 | {
121 | persons.add(c);
122 | }
123 |
124 | public void addBorrower(Borrower b)
125 | {
126 | persons.add(b);
127 | }
128 |
129 |
130 | public void addLoan(Loan l)
131 | {
132 | loans.add(l);
133 | }
134 |
135 | /*----------------------------------------------*/
136 |
137 | /*-----------Finding People in Library--------------*/
138 | public Borrower findBorrower()
139 | {
140 | System.out.println("\nEnter Borrower's ID: ");
141 |
142 | int id = 0;
143 |
144 | Scanner scanner = new Scanner(System.in);
145 |
146 | try{
147 | id = scanner.nextInt();
148 | }
149 | catch (java.util.InputMismatchException e)
150 | {
151 | System.out.println("\nInvalid Input");
152 | }
153 |
154 | for (int i = 0; i < persons.size(); i++)
155 | {
156 | if (persons.get(i).getID() == id && persons.get(i).getClass().getSimpleName().equals("Borrower"))
157 | return (Borrower)(persons.get(i));
158 | }
159 |
160 | System.out.println("\nSorry this ID didn't match any Borrower's ID.");
161 | return null;
162 | }
163 |
164 | public Clerk findClerk()
165 | {
166 | System.out.println("\nEnter Clerk's ID: ");
167 |
168 | int id = 0;
169 |
170 | Scanner scanner = new Scanner(System.in);
171 |
172 | try{
173 | id = scanner.nextInt();
174 | }
175 | catch (java.util.InputMismatchException e)
176 | {
177 | System.out.println("\nInvalid Input");
178 | }
179 |
180 | for (int i = 0; i < persons.size(); i++)
181 | {
182 | if (persons.get(i).getID() == id && persons.get(i).getClass().getSimpleName().equals("Clerk"))
183 | return (Clerk)(persons.get(i));
184 | }
185 |
186 | System.out.println("\nSorry this ID didn't match any Clerk's ID.");
187 | return null;
188 | }
189 |
190 | /*------- FUNCS. on Books In Library--------------*/
191 | public void addBookinLibrary(Book b)
192 | {
193 | booksInLibrary.add(b);
194 | }
195 |
196 | //When this function is called, only the pointer of the book placed in booksInLibrary is removed. But the real object of book
197 | //is still there in memory because pointers of that book placed in IssuedBooks and ReturnedBooks are still pointing to that book. And we
198 | //are maintaining those pointers so that we can maintain history.
199 | //But if we donot want to maintain history then we can delete those pointers placed in IssuedBooks and ReturnedBooks as well which are
200 | //pointing to that book. In this way the book will be really removed from memory.
201 | public void removeBookfromLibrary(Book b)
202 | {
203 | boolean delete = true;
204 |
205 | //Checking if this book is currently borrowed by some borrower
206 | for (int i = 0; i < persons.size() && delete; i++)
207 | {
208 | if (persons.get(i).getClass().getSimpleName().equals("Borrower"))
209 | {
210 | ArrayList borBooks = ((Borrower)(persons.get(i))).getBorrowedBooks();
211 |
212 | for (int j = 0; j < borBooks.size() && delete; j++)
213 | {
214 | if (borBooks.get(j).getBook() == b)
215 | {
216 | delete = false;
217 | System.out.println("This particular book is currently borrowed by some borrower.");
218 | }
219 | }
220 | }
221 | }
222 |
223 | if (delete)
224 | {
225 | System.out.println("\nCurrently this book is not borrowed by anyone.");
226 | ArrayList hRequests = b.getHoldRequests();
227 |
228 | if(!hRequests.isEmpty())
229 | {
230 | System.out.println("\nThis book might be on hold requests by some borrowers. Deleting this book will delete the relevant hold requests too.");
231 | System.out.println("Do you still want to delete the book? (y/n)");
232 |
233 | Scanner sc = new Scanner(System.in);
234 |
235 | while (true)
236 | {
237 | String choice = sc.next();
238 |
239 | if(choice.equals("y") || choice.equals("n"))
240 | {
241 | if(choice.equals("n"))
242 | {
243 | System.out.println("\nDelete Unsuccessful.");
244 | return;
245 | }
246 | else
247 | {
248 | //Empty the books hold request array
249 | //Delete the hold request from the borrowers too
250 | for (int i = 0; i < hRequests.size() && delete; i++)
251 | {
252 | HoldRequest hr = hRequests.get(i);
253 | hr.getBorrower().removeHoldRequest(hr);
254 | holdRequestsOperations.removeHoldRequest();
255 | }
256 | }
257 | }
258 | else
259 | System.out.println("Invalid Input. Enter (y/n): ");
260 | }
261 |
262 | }
263 | else
264 | System.out.println("This book has no hold requests.");
265 |
266 | booksInLibrary.remove(b);
267 | System.out.println("The book is successfully removed.");
268 | }
269 | else
270 | System.out.println("\nDelete Unsuccessful.");
271 | }
272 |
273 |
274 |
275 | // Searching Books on basis of title, Subject or Author
276 | public ArrayList searchForBooks() throws IOException
277 | {
278 | String choice;
279 | String title = "", subject = "", author = "";
280 |
281 | Scanner sc = new Scanner(System.in);
282 | BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
283 |
284 | while (true)
285 | {
286 | System.out.println("\nEnter either '1' or '2' or '3' for search by Title, Subject or Author of Book respectively: ");
287 | choice = sc.next();
288 |
289 | if (choice.equals("1") || choice.equals("2") || choice.equals("3"))
290 | break;
291 | else
292 | System.out.println("\nWrong Input!");
293 | }
294 |
295 | if (choice.equals("1"))
296 | {
297 | System.out.println("\nEnter the Title of the Book: ");
298 | title = reader.readLine();
299 | }
300 |
301 | else if (choice.equals("2"))
302 | {
303 | System.out.println("\nEnter the Subject of the Book: ");
304 | subject = reader.readLine();
305 | }
306 |
307 | else
308 | {
309 | System.out.println("\nEnter the Author of the Book: ");
310 | author = reader.readLine();
311 | }
312 |
313 | ArrayList matchedBooks = new ArrayList();
314 |
315 | //Retrieving all the books which matched the user's search query
316 | for(int i = 0; i < booksInLibrary.size(); i++)
317 | {
318 | Book b = booksInLibrary.get(i);
319 |
320 | if (choice.equals("1"))
321 | {
322 | if (b.getTitle().equals(title))
323 | matchedBooks.add(b);
324 | }
325 | else if (choice.equals("2"))
326 | {
327 | if (b.getSubject().equals(subject))
328 | matchedBooks.add(b);
329 | }
330 | else
331 | {
332 | if (b.getAuthor().equals(author))
333 | matchedBooks.add(b);
334 | }
335 | }
336 |
337 | //Printing all the matched Books
338 | if (!matchedBooks.isEmpty())
339 | {
340 | System.out.println("\nThese books are found: \n");
341 |
342 | System.out.println("------------------------------------------------------------------------------");
343 | System.out.println("No.\t\tTitle\t\t\tAuthor\t\t\tSubject");
344 | System.out.println("------------------------------------------------------------------------------");
345 |
346 | for (int i = 0; i < matchedBooks.size(); i++)
347 | {
348 | System.out.print(i + "-" + "\t\t");
349 | matchedBooks.get(i).printInfo();
350 | System.out.print("\n");
351 | }
352 |
353 | return matchedBooks;
354 | }
355 | else
356 | {
357 | System.out.println("\nSorry. No Books were found related to your query.");
358 | return null;
359 | }
360 | }
361 |
362 |
363 |
364 | // View Info of all Books in Library
365 | public void viewAllBooks()
366 | {
367 | if (!booksInLibrary.isEmpty())
368 | {
369 | System.out.println("\nBooks are: ");
370 |
371 | System.out.println("------------------------------------------------------------------------------");
372 | System.out.println("No.\t\tTitle\t\t\tAuthor\t\t\tSubject");
373 | System.out.println("------------------------------------------------------------------------------");
374 |
375 | for (int i = 0; i < booksInLibrary.size(); i++)
376 | {
377 | System.out.print(i + "-" + "\t\t");
378 | booksInLibrary.get(i).printInfo();
379 | System.out.print("\n");
380 | }
381 | }
382 | else
383 | System.out.println("\nCurrently, Library has no books.");
384 | }
385 |
386 |
387 | //Computes total fine for all loans of a borrower
388 | public double computeFine2(Borrower borrower)
389 | {
390 | System.out.println("---------------------------------------------------------------------------------------------------------------------------------------------------------------------");
391 | System.out.println("No.\t\tBook's Title\t\tBorrower's Name\t\t\tIssued Date\t\t\tReturned Date\t\t\t\tFine(Rs)");
392 | System.out.println("-------------------------------------------------------------------------------------------------------------------------------------------------------------------");
393 |
394 | double totalFine = 0;
395 | double per_loan_fine = 0;
396 |
397 | for (int i = 0; i < loans.size(); i++)
398 | {
399 | Loan l = loans.get(i);
400 |
401 | if ((l.getBorrower() == borrower))
402 | {
403 | per_loan_fine = l.computeFine1();
404 | System.out.print(i + "-" + "\t\t" + loans.get(i).getBook().getTitle() + "\t\t\t" + loans.get(i).getBorrower().getName() + "\t\t" + loans.get(i).getIssuedDate() + "\t\t\t" + loans.get(i).getReturnDate() + "\t\t\t\t" + per_loan_fine + "\n");
405 |
406 | totalFine += per_loan_fine;
407 | }
408 | }
409 |
410 | return totalFine;
411 | }
412 |
413 |
414 | public void createPerson(char x)
415 | {
416 | Scanner sc = new Scanner(System.in);
417 | BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
418 |
419 | System.out.println("\nEnter Name: ");
420 | String n = "";
421 | try {
422 | n = reader.readLine();
423 | } catch (IOException ex) {
424 | Logger.getLogger(Library.class.getName()).log(Level.SEVERE, null, ex);
425 | }
426 | System.out.println("Enter Address: ");
427 | String address = "";
428 | try {
429 | address = reader.readLine();
430 | } catch (IOException ex) {
431 | Logger.getLogger(Library.class.getName()).log(Level.SEVERE, null, ex);
432 | }
433 |
434 | int phone = 0;
435 |
436 | try{
437 | System.out.println("Enter Phone Number: ");
438 | phone = sc.nextInt();
439 | }
440 | catch (java.util.InputMismatchException e)
441 | {
442 | System.out.println("\nInvalid Input.");
443 | }
444 |
445 | //If clerk is to be created
446 | if (x == 'c')
447 | {
448 | double salary = 0;
449 |
450 | try{
451 | System.out.println("Enter Salary: ");
452 | salary = sc.nextDouble();
453 | }
454 | catch (java.util.InputMismatchException e)
455 | {
456 | System.out.println("\nInvalid Input.");
457 | }
458 |
459 | Clerk c = new Clerk(-1,n,address,phone,salary,-1);
460 | addClerk(c);
461 |
462 | System.out.println("\nClerk with name " + n + " created successfully.");
463 | System.out.println("\nYour ID is : " + c.getID());
464 | System.out.println("Your Password is : " + c.getPassword());
465 | }
466 |
467 | //If librarian is to be created
468 | else if (x == 'l')
469 | {
470 | double salary = 0;
471 | try{
472 | System.out.println("Enter Salary: ");
473 | salary = sc.nextDouble();
474 | }
475 | catch (java.util.InputMismatchException e)
476 | {
477 | System.out.println("\nInvalid Input.");
478 | }
479 |
480 | Librarian l = new Librarian(-1,n,address,phone,salary,-1);
481 | if(Librarian.addLibrarian(l))
482 | {
483 | System.out.println("\nLibrarian with name " + n + " created successfully.");
484 | System.out.println("\nYour ID is : " + l.getID());
485 | System.out.println("Your Password is : " + l.getPassword());
486 | }
487 | }
488 |
489 | //If borrower is to be created
490 | else
491 | {
492 | Borrower b = new Borrower(-1,n,address,phone);
493 | addBorrower(b);
494 | System.out.println("\nBorrower with name " + n + " created successfully.");
495 |
496 | System.out.println("\nYour ID is : " + b.getID());
497 | System.out.println("Your Password is : " + b.getPassword());
498 | }
499 | }
500 |
501 |
502 |
503 | public void createBook(String title, String subject, String author)
504 | {
505 | Book b = new Book(-1,title,subject,author,false);
506 |
507 | addBookinLibrary(b);
508 |
509 | System.out.println("\nBook with Title " + b.getTitle() + " is successfully created.");
510 | }
511 |
512 |
513 |
514 | // Called when want an access to Portal
515 | public Person login()
516 | {
517 | Scanner input = new Scanner(System.in);
518 |
519 | int id = 0;
520 | String password = "";
521 |
522 | System.out.println("\nEnter ID: ");
523 |
524 | try{
525 | id = input.nextInt();
526 | }
527 | catch (java.util.InputMismatchException e)
528 | {
529 | System.out.println("\nInvalid Input");
530 | }
531 |
532 | System.out.println("Enter Password: ");
533 | password = input.next();
534 |
535 | for (int i = 0; i < persons.size(); i++)
536 | {
537 | if (persons.get(i).getID() == id && persons.get(i).getPassword().equals(password))
538 | {
539 | System.out.println("\nLogin Successful");
540 | return persons.get(i);
541 | }
542 | }
543 |
544 | if(librarian!=null)
545 | {
546 | if (librarian.getID() == id && librarian.getPassword().equals(password))
547 | {
548 | System.out.println("\nLogin Successful");
549 | return librarian;
550 | }
551 | }
552 |
553 | System.out.println("\nSorry! Wrong ID or Password");
554 | return null;
555 | }
556 |
557 |
558 | // History when a Book was Issued and was Returned!
559 | public void viewHistory()
560 | {
561 | if (!loans.isEmpty())
562 | {
563 | System.out.println("\nIssued Books are: ");
564 |
565 | System.out.println("------------------------------------------------------------------------------------------------------------------------------------------------------");
566 | System.out.println("No.\tBook's Title\tBorrower's Name\t Issuer's Name\t\tIssued Date\t\t\tReceiver's Name\t\tReturned Date\t\tFine Paid");
567 | System.out.println("------------------------------------------------------------------------------------------------------------------------------------------------------");
568 |
569 | for (int i = 0; i < loans.size(); i++)
570 | {
571 | if(loans.get(i).getIssuer()!=null)
572 | System.out.print(i + "-" + "\t" + loans.get(i).getBook().getTitle() + "\t\t\t" + loans.get(i).getBorrower().getName() + "\t\t" + loans.get(i).getIssuer().getName() + "\t " + loans.get(i).getIssuedDate());
573 |
574 | if (loans.get(i).getReceiver() != null)
575 | {
576 | System.out.print("\t" + loans.get(i).getReceiver().getName() + "\t\t" + loans.get(i).getReturnDate() +"\t " + loans.get(i).getFineStatus() + "\n");
577 | }
578 | else
579 | System.out.print("\t\t" + "--" + "\t\t\t" + "--" + "\t\t" + "--" + "\n");
580 | }
581 | }
582 | else
583 | System.out.println("\nNo issued books.");
584 | }
585 |
586 |
587 |
588 |
589 |
590 |
591 |
592 |
593 |
594 | //---------------------------------------------------------------------------------------//
595 | /*--------------------------------IN- COLLABORATION WITH DATA BASE------------------------------------------*/
596 |
597 | // Making Connection With Database
598 | public Connection makeConnection()
599 | {
600 | try
601 | {
602 | String host = "jdbc:derby://localhost:1527/LMS";
603 | String uName = "haris";
604 | String uPass= "123";
605 | Connection con = DriverManager.getConnection( host, uName, uPass );
606 | return con;
607 | }
608 | catch ( SQLException err )
609 | {
610 | System.out.println( err.getMessage( ) );
611 | return null;
612 | }
613 | }
614 |
615 |
616 | // Loading all info in code via Database.
617 | public void populateLibrary(Connection con) throws SQLException, IOException
618 | {
619 | Library lib = this;
620 | Statement stmt = con.createStatement( );
621 |
622 | /* --- Populating Book ----*/
623 | String SQL = "SELECT * FROM BOOK";
624 | ResultSet rs = stmt.executeQuery( SQL );
625 |
626 | if(!rs.next())
627 | {
628 | System.out.println("\nNo Books Found in Library");
629 | }
630 | else
631 | {
632 | int maxID = 0;
633 |
634 | do
635 | {
636 | if(rs.getString("TITLE") !=null && rs.getString("AUTHOR")!=null && rs.getString("SUBJECT")!=null && rs.getInt("ID")!=0)
637 | {
638 | String title=rs.getString("TITLE");
639 | String author=rs.getString("AUTHOR");
640 | String subject=rs.getString("SUBJECT");
641 | int id= rs.getInt("ID");
642 | boolean issue=rs.getBoolean("IS_ISSUED");
643 | Book b = new Book(id,title,subject,author,issue);
644 | addBookinLibrary(b);
645 |
646 | if (maxID < id)
647 | maxID = id;
648 | }
649 | }while(rs.next());
650 |
651 | // setting Book Count
652 | Book.setIDCount(maxID);
653 | }
654 |
655 | /* ----Populating Clerks----*/
656 |
657 | SQL="SELECT ID,PNAME,ADDRESS,PASSWORD,PHONE_NO,SALARY,DESK_NO FROM PERSON INNER JOIN CLERK ON ID=C_ID INNER JOIN STAFF ON S_ID=C_ID";
658 |
659 | rs=stmt.executeQuery(SQL);
660 |
661 | if(!rs.next())
662 | {
663 | System.out.println("No clerks Found in Library");
664 | }
665 | else
666 | {
667 | do
668 | {
669 | int id=rs.getInt("ID");
670 | String cname=rs.getString("PNAME");
671 | String adrs=rs.getString("ADDRESS");
672 | int phn=rs.getInt("PHONE_NO");
673 | double sal=rs.getDouble("SALARY");
674 | int desk=rs.getInt("DESK_NO");
675 | Clerk c = new Clerk(id,cname,adrs,phn,sal,desk);
676 |
677 | addClerk(c);
678 | }
679 | while(rs.next());
680 |
681 | }
682 |
683 | /*-----Populating Librarian---*/
684 | SQL="SELECT ID,PNAME,ADDRESS,PASSWORD,PHONE_NO,SALARY,OFFICE_NO FROM PERSON INNER JOIN LIBRARIAN ON ID=L_ID INNER JOIN STAFF ON S_ID=L_ID";
685 |
686 | rs=stmt.executeQuery(SQL);
687 | if(!rs.next())
688 | {
689 | System.out.println("No Librarian Found in Library");
690 | }
691 | else
692 | {
693 | do
694 | {
695 | int id=rs.getInt("ID");
696 | String lname=rs.getString("PNAME");
697 | String adrs=rs.getString("ADDRESS");
698 | int phn=rs.getInt("PHONE_NO");
699 | double sal=rs.getDouble("SALARY");
700 | int off=rs.getInt("OFFICE_NO");
701 | Librarian l= new Librarian(id,lname,adrs,phn,sal,off);
702 |
703 | Librarian.addLibrarian(l);
704 |
705 | }while(rs.next());
706 |
707 | }
708 |
709 | /*---Populating Borrowers (partially)!!!!!!--------*/
710 |
711 | SQL="SELECT ID,PNAME,ADDRESS,PASSWORD,PHONE_NO FROM PERSON INNER JOIN BORROWER ON ID=B_ID";
712 |
713 | rs=stmt.executeQuery(SQL);
714 |
715 | if(!rs.next())
716 | {
717 | System.out.println("No Borrower Found in Library");
718 | }
719 | else
720 | {
721 | do
722 | {
723 | int id=rs.getInt("ID");
724 | String name=rs.getString("PNAME");
725 | String adrs=rs.getString("ADDRESS");
726 | int phn=rs.getInt("PHONE_NO");
727 |
728 | Borrower b= new Borrower(id,name,adrs,phn);
729 | addBorrower(b);
730 |
731 | }while(rs.next());
732 |
733 | }
734 |
735 | /*----Populating Loan----*/
736 |
737 | SQL="SELECT * FROM LOAN";
738 |
739 | rs=stmt.executeQuery(SQL);
740 | if(!rs.next())
741 | {
742 | System.out.println("No Books Issued Yet!");
743 | }
744 | else
745 | {
746 | do
747 | {
748 | int borid=rs.getInt("BORROWER");
749 | int bokid=rs.getInt("BOOK");
750 | int iid=rs.getInt("ISSUER");
751 | Integer rid=(Integer)rs.getObject("RECEIVER");
752 | int rd=0;
753 | Date rdate;
754 |
755 | Date idate=new Date (rs.getTimestamp("ISS_DATE").getTime());
756 |
757 | if(rid!=null) // if there is a receiver
758 | {
759 | rdate=new Date (rs.getTimestamp("RET_DATE").getTime());
760 | rd=(int)rid;
761 | }
762 | else
763 | {
764 | rdate=null;
765 | }
766 |
767 | boolean fineStatus = rs.getBoolean("FINE_PAID");
768 |
769 | boolean set=true;
770 |
771 | Borrower bb = null;
772 |
773 |
774 | for(int i=0;i books = getBooks();
831 |
832 | for(int k=0;k persons = lib.getPersons();
866 |
867 | for(int i=0;i books = lib.getBooks();
879 |
880 | for(int i=0;i books = loans;
931 |
932 | for(int i=0;i persons = lib.getPersons();
946 |
947 | /* Setting Person ID Count */
948 | int max=0;
949 |
950 | for(int i=0;i books = lib.getBooks();
1103 |
1104 | /*Filling Book's Table*/
1105 | for(int i=0;i