Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue fixed Suggestion of refactorizing code #7 #24

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .classpath
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry kind="src" path="Project/src"/>
<classpathentry kind="lib" path="Project/derbyclient-10.2.2.0.jar"/>
<classpathentry kind="output" path="Project/build/classes"/>
</classpath>
3 changes: 3 additions & 0 deletions .idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/azure/azureSettings.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions .idea/libraries/derbyclient_10_2_2_0.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 17 additions & 0 deletions .project
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>Library-Management-System-JAVA-master</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>
11 changes: 11 additions & 0 deletions Library-Management-System-JAVA-master.iml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/Project/src" isTestSource="false" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>
Binary file modified Project/build/classes/LMS/Book.class
Binary file not shown.
Binary file modified Project/build/classes/LMS/Borrower.class
Binary file not shown.
Binary file modified Project/build/classes/LMS/Clerk.class
Binary file not shown.
Binary file modified Project/build/classes/LMS/HoldRequest.class
Binary file not shown.
Binary file added Project/build/classes/LMS/HoldRequestActions.class
Binary file not shown.
Binary file not shown.
Binary file modified Project/build/classes/LMS/Librarian.class
Binary file not shown.
Binary file modified Project/build/classes/LMS/Library.class
Binary file not shown.
Binary file modified Project/build/classes/LMS/Loan.class
Binary file not shown.
Binary file modified Project/build/classes/LMS/Main.class
Binary file not shown.
Binary file modified Project/build/classes/LMS/Person.class
Binary file not shown.
Binary file modified Project/build/classes/LMS/Staff.class
Binary file not shown.
683 changes: 517 additions & 166 deletions Project/nbproject/build-impl.xml

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions Project/nbproject/genfiles.properties
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
build.xml.data.CRC32=507ddfa4
build.xml.script.CRC32=5d5937f5
build.xml.stylesheet.CRC32=8064a381@1.80.1.48
build.xml.stylesheet.CRC32=f85dc8f2@1.106.0.48
# This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml.
# Do not edit this file. You may delete it but then the IDE will never regenerate such files for you.
nbproject/build-impl.xml.data.CRC32=507ddfa4
nbproject/build-impl.xml.script.CRC32=0ebf329b
nbproject/build-impl.xml.stylesheet.CRC32=830a3534@1.80.1.48
nbproject/build-impl.xml.script.CRC32=0eec8d9b
nbproject/build-impl.xml.stylesheet.CRC32=12e0a6c2@1.106.0.48
2 changes: 1 addition & 1 deletion Project/nbproject/private/private.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ do.depend=false
do.jar=true
javac.debug=true
javadoc.preview=true
user.properties.file=C:\\Users\\PAKLAP.pk\\AppData\\Roaming\\NetBeans\\8.2\\build.properties
user.properties.file=C:\\Users\\2106802\\AppData\\Roaming\\NetBeans\\17\\build.properties
9 changes: 8 additions & 1 deletion Project/nbproject/private/private.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,14 @@
<editor-bookmarks xmlns="http://www.netbeans.org/ns/editor-bookmarks/2" lastBookmarkId="0"/>
<open-files xmlns="http://www.netbeans.org/ns/projectui-open-files/2">
<group>
<file>file:/D:/FAST/5th%20Semester%20%20%20%20(Fall%202017)/Object%20Oriented%20Analysis%20and%20Design/Assignments/Assignment%201/Library%20Management%20System/Project/src/LMS/Main.java</file>
<file>file:/C:/Users/2106802/Downloads/Library-Management-System-JAVA-master/Project/src/LMS/HoldRequestOperations.java</file>
<file>file:/C:/Users/2106802/Downloads/Library-Management-System-JAVA-master/Project/src/LMS/Book.java</file>
<file>file:/C:/Users/2106802/Downloads/Library-Management-System-JAVA-master/Project/src/LMS/Main.java</file>
<file>file:/C:/Users/2106802/Downloads/Library-Management-System-JAVA-master/Project/src/LMS/HoldRequest.java</file>
<file>file:/C:/Users/2106802/Downloads/Library-Management-System-JAVA-master/Project/src/LMS/Library.java</file>
<file>file:/C:/Users/2106802/Downloads/Library-Management-System-JAVA-master/Project/src/LMS/Librarian.java</file>
<file>file:/C:/Users/2106802/Downloads/Library-Management-System-JAVA-master/Project/src/LMS/HoldRequestActions.java</file>
<file>file:/C:/Users/2106802/Downloads/Library-Management-System-JAVA-master/Project/src/LMS/Borrower.java</file>
</group>
</open-files>
</project-private>
16 changes: 14 additions & 2 deletions Project/nbproject/project.properties
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,12 @@ build.test.results.dir=${build.dir}/test/results
#debug.transport=dt_socket
debug.classpath=\
${run.classpath}
debug.modulepath=\
${run.modulepath}
debug.test.classpath=\
${run.test.classpath}
debug.test.modulepath=\
${run.test.modulepath}
# Files in build.classes.dir which should be excluded from distribution jar
dist.archive.excludes=
# This directory is removed when the project is cleaned:
Expand All @@ -29,22 +33,26 @@ dist.jar=${dist.dir}/Library_Management_System.jar
dist.javadoc.dir=${dist.dir}/javadoc
endorsed.classpath=
excludes=
file.reference.derbyclient-10.2.2.0.jar=derbyclient-10.2.2.0.jar
file.reference.mysql-connector-j-8.3.0.jar=C:\\Users\\2106802\\Downloads\\mysql-connector-j-8.3.0\\mysql-connector-j-8.3.0.jar
includes=**
jar.compress=false
javac.classpath=\
${file.reference.derbyclient-10.2.2.0.jar}
${file.reference.mysql-connector-j-8.3.0.jar}
# Space-separated list of extra javac options
javac.compilerargs=
javac.deprecation=false
javac.external.vm=true
javac.modulepath=
javac.processormodulepath=
javac.processorpath=\
${javac.classpath}
javac.source=1.8
javac.target=1.8
javac.test.classpath=\
${javac.classpath}:\
${build.classes.dir}
javac.test.modulepath=\
${javac.modulepath}
javac.test.processorpath=\
${javac.test.classpath}
javadoc.additionalparam=
Expand All @@ -70,9 +78,13 @@ run.classpath=\
# You may also define separate properties like run-sys-prop.name=value instead of -Dname=value.
# To set system properties for unit tests define test-sys-prop.name=value:
run.jvmargs=
run.modulepath=\
${javac.modulepath}
run.test.classpath=\
${javac.test.classpath}:\
${build.test.classes.dir}
run.test.modulepath=\
${javac.test.modulepath}
source.encoding=UTF-8
src.dir=src
test.src.dir=test
33 changes: 17 additions & 16 deletions Project/src/LMS/Book.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public class Book {
private String subject; // Subject to which a book is related!
private String author; // Author of book!
private boolean isIssued; // this will be true if the book is currently issued to some borrower.
private HoldRequestOperations holdRequestsOperations =new HoldRequestOperations();
private HoldRequestOperations holdRequests;
static int currentIdNumber = 0; //This will be unique for every book, since it will be incremented when everytime
//when a book is created

Expand All @@ -31,25 +31,26 @@ public Book(int id,String t, String s, String a, boolean issued) // Parameter
subject = s;
author = a;
isIssued = issued;
this.holdRequests = holdRequests;

}


// printing all hold req on a book.
public void printHoldRequests()
{
if (!holdRequestsOperations.holdRequests.isEmpty())
if (!holdRequests.holdRequests.isEmpty())
{
System.out.println("\nHold Requests are: ");

System.out.println("---------------------------------------------------------------------------------------------------------------------------------------");
System.out.println("No.\t\tBook's Title\t\t\tBorrower's Name\t\t\tRequest Date");
System.out.println("---------------------------------------------------------------------------------------------------------------------------------------");

for (int i = 0; i < holdRequestsOperations.holdRequests.size(); i++)
for (int i = 0; i < holdRequests.holdRequests.size(); i++)
{
System.out.print(i + "-" + "\t\t");
holdRequestsOperations.holdRequests.get(i).print();
holdRequests.holdRequests.get(i).print();
}
}
else
Expand Down Expand Up @@ -135,7 +136,7 @@ public int getID()

public ArrayList<HoldRequest> getHoldRequests()
{
return holdRequestsOperations.holdRequests;
return holdRequests.holdRequests;
}
/*-----------------------------------*/

Expand All @@ -155,7 +156,7 @@ public void placeBookOnHold(Borrower bor)
{
HoldRequest hr = new HoldRequest(bor,this, new Date());

holdRequestsOperations.addHoldRequest(hr); //Add this hold request to holdRequests queue of this book
holdRequests.addHoldRequest(hr); //Add this hold request to holdRequests queue of this book
bor.addHoldRequest(hr); //Add this hold request to that particular borrower's class as well

System.out.println("\nThe book " + title + " has been successfully placed on hold by borrower " + bor.getName() + ".\n");
Expand All @@ -181,9 +182,9 @@ public void makeHoldRequest(Borrower borrower)


//If that borrower has already requested for that particular book. Then he isn't allowed to make the same request again.
for (int i = 0; i < holdRequestsOperations.holdRequests.size(); i++)
for (int i = 0; i < holdRequests.holdRequests.size(); i++)
{
if ((holdRequestsOperations.holdRequests.get(i).getBorrower() == borrower))
if ((holdRequests.holdRequests.get(i).getBorrower() == borrower))
{
makeRequest = false;
break;
Expand All @@ -202,7 +203,7 @@ public void makeHoldRequest(Borrower borrower)
// Getting Info of a Hold Request
public void serviceHoldRequest(HoldRequest hr)
{
holdRequestsOperations.removeHoldRequest();
holdRequests.removeHoldRequest();
hr.getBorrower().removeHoldRequest(hr);
}

Expand All @@ -214,7 +215,7 @@ public void issueBook(Borrower borrower, Staff staff)
//First deleting the expired hold requests
Date today = new Date();

ArrayList<HoldRequest> hRequests = holdRequestsOperations.holdRequests;
ArrayList<HoldRequest> hRequests = holdRequests.holdRequests;

for (int i = 0; i < hRequests.size(); i++)
{
Expand All @@ -226,7 +227,7 @@ public void issueBook(Borrower borrower, Staff staff)

if(days>Library.getInstance().getHoldRequestExpiry())
{
holdRequestsOperations.removeHoldRequest();
holdRequests.removeHoldRequest();
hr.getBorrower().removeHoldRequest(hr);
}
}
Expand All @@ -247,22 +248,22 @@ public void issueBook(Borrower borrower, Staff staff)

else
{
if (!holdRequestsOperations.holdRequests.isEmpty())
if (!holdRequests.holdRequests.isEmpty())
{
boolean hasRequest = false;

for (int i = 0; i < holdRequestsOperations.holdRequests.size() && !hasRequest;i++)
for (int i = 0; i < holdRequests.holdRequests.size() && !hasRequest;i++)
{
if (holdRequestsOperations.holdRequests.get(i).getBorrower() == borrower)
if (holdRequests.holdRequests.get(i).getBorrower() == borrower)
hasRequest = true;

}

if (hasRequest)
{
//If this particular borrower has the earliest request for this book
if (holdRequestsOperations.holdRequests.get(0).getBorrower() == borrower)
serviceHoldRequest(holdRequestsOperations.holdRequests.get(0));
if (holdRequests.holdRequests.get(0).getBorrower() == borrower)
serviceHoldRequest(holdRequests.holdRequests.get(0));

else
{
Expand Down
21 changes: 21 additions & 0 deletions Project/src/LMS/HoldRequestActions.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/*
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Interface.java to edit this template
*/
package LMS;

/**
*
* @author 2106802
*/
public interface HoldRequestActions {

public void addHoldRequest(HoldRequest hr);

public void removeHoldRequest (HoldRequest hr); public void removeHoldRequest();

public void printHoldRequest();

public void serviceHoldRequest(HoldRequest hr);

}
17 changes: 16 additions & 1 deletion Project/src/LMS/HoldRequestOperations.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import java.util.ArrayList;

public class HoldRequestOperations {
public class HoldRequestOperations implements HoldRequestActions {

static ArrayList <HoldRequest> holdRequests;

Expand All @@ -23,4 +23,19 @@ public void removeHoldRequest()
holdRequests.remove(0);
}
}

@Override
public void removeHoldRequest(HoldRequest hr) {
throw new UnsupportedOperationException("Not supported yet."); // Generated from nbfs://nbhost/SystemFileSystem/Templates/Classes/Code/GeneratedMethodBody
}

@Override
public void printHoldRequest() {
throw new UnsupportedOperationException("Not supported yet."); // Generated from nbfs://nbhost/SystemFileSystem/Templates/Classes/Code/GeneratedMethodBody
}

@Override
public void serviceHoldRequest(HoldRequest hr) {
throw new UnsupportedOperationException("Not supported yet."); // Generated from nbfs://nbhost/SystemFileSystem/Templates/Classes/Code/GeneratedMethodBody
}
}
18 changes: 15 additions & 3 deletions Project/src/LMS/Library.java
Original file line number Diff line number Diff line change
Expand Up @@ -599,12 +599,24 @@ public Connection makeConnection()
{
try
{
String host = "jdbc:derby://localhost:1527/LMS";
String uName = "haris";
String uPass= "123";
// try {
//String host = "jdbc:derby://localhost:3306/LMS";
//String uName = "haris";
//String uPass= "123";

Class.forName("com.mysql.cj.jdbc.Driver");
//} catch (ClassNotFoundException ex) {
// Logger.getLogger(Library.class.getName()).log(Level.SEVERE, null, ex);
String host = "jdbc:mysql://localhost:3306/LMS";
String uName = "root";
String uPass= "admin";
Connection con = DriverManager.getConnection( host, uName, uPass );
return con;
}
catch (ClassNotFoundException ex) {
Logger.getLogger(Library.class.getName()).log(Level.SEVERE, null, ex);
return null;
}
catch ( SQLException err )
{
System.out.println( err.getMessage( ) );
Expand Down