Skip to content

Commit c1793a6

Browse files
Uploading Source Code Files
1 parent 115d810 commit c1793a6

17 files changed

+6673
-0
lines changed

Books.java

+155
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,155 @@
1+
/*
2+
* To change this license header, choose License Headers in Project Properties.
3+
* To change this template file, choose Tools | Templates
4+
* and open the template in the editor.
5+
*/
6+
package library;
7+
8+
import java.util.*;
9+
import java.io.*;
10+
import java.util.Iterator;
11+
import java.util.LinkedList;
12+
import java.util.List;
13+
14+
/**
15+
*
16+
* @author Minahil Imtiaz
17+
*/
18+
public class Books {
19+
20+
private int book_id;
21+
private String author;
22+
private String title;
23+
private String subject;
24+
private int quantity; //a book may have more than one quantity
25+
26+
Books() {
27+
this.book_id = -1;
28+
this.author = " ";
29+
this.title = " ";
30+
this.subject = " ";
31+
this.quantity = 0;
32+
33+
}
34+
35+
Books(int book_id, String author, String title, String subject, int quantity) {
36+
37+
this.book_id = book_id;
38+
this.author = author;
39+
this.title = title;
40+
this.subject = subject;
41+
this.quantity = quantity;
42+
}
43+
44+
public void SetBookId(int book_id) {
45+
this.book_id = book_id;
46+
47+
}
48+
49+
public void SetAuthor(String author) {
50+
this.author = author;
51+
dbConnectivity db = new dbConnectivity();
52+
db.ChangeBookInfo(book_id, author, 2);
53+
}
54+
55+
public void SetTitle(String title) {
56+
this.title = title;
57+
dbConnectivity db = new dbConnectivity();
58+
db.ChangeBookInfo(book_id, title, 1);
59+
}
60+
61+
public void SetQuantity(int quantity) {
62+
this.quantity = quantity;
63+
dbConnectivity db = new dbConnectivity();
64+
db.UpdateBookQuantity(this.quantity, this.book_id);
65+
66+
}
67+
68+
public void SetSubject(String subject) {
69+
70+
this.subject = subject;
71+
dbConnectivity db = new dbConnectivity();
72+
db.ChangeBookInfo(book_id, subject, 3);
73+
74+
}
75+
76+
public String GetTitle() {
77+
78+
dbConnectivity db = new dbConnectivity();
79+
String titleofbook = db.GetTitleofBook(this.book_id);
80+
return titleofbook;
81+
}
82+
83+
public String GetAuthor() {
84+
dbConnectivity db = new dbConnectivity();
85+
String authorofbook = db.GetAuthorofBook(this.book_id);
86+
return authorofbook;
87+
}
88+
89+
public int GetBookId() {
90+
91+
return this.book_id;
92+
93+
}
94+
95+
public String GetSubject() {
96+
dbConnectivity db = new dbConnectivity();
97+
String subjectofbook = db.GetSubjectofBook(this.book_id);
98+
return subjectofbook;
99+
// return this.subject;
100+
}
101+
102+
public Books GetaBook() {
103+
dbConnectivity db = new dbConnectivity();
104+
Books MyBook = db.GetaBookbyId(this.book_id);
105+
return MyBook;
106+
}
107+
108+
public int GetQuantity() {
109+
dbConnectivity db = new dbConnectivity();
110+
int quantity_available = db.GetQuantityofBook(this.book_id);
111+
// return this.quantity;
112+
return quantity_available;
113+
114+
}
115+
116+
public boolean ChekcAvailability(int book_id) {
117+
dbConnectivity db = new dbConnectivity();
118+
int quantity_available = db.GetQuantityofBook(this.book_id);
119+
if (quantity_available <= 0) {
120+
return false;
121+
} else {
122+
return true;
123+
}
124+
125+
}
126+
127+
public void DecreaseQuantity() {
128+
if (quantity > 0) {
129+
this.quantity = this.quantity - 1;
130+
dbConnectivity db = new dbConnectivity();
131+
db.UpdateBookQuantity(this.quantity, book_id);
132+
}
133+
134+
}
135+
136+
public void IncreaseQuantity() {
137+
this.quantity = this.quantity + 1;
138+
dbConnectivity db = new dbConnectivity();
139+
db.UpdateBookQuantity(this.quantity, book_id);
140+
}
141+
142+
public String PrintInformation() {
143+
boolean available = ChekcAvailability(this.book_id);
144+
String status;
145+
if (available == true) {
146+
status = "available";
147+
} else {
148+
status = "not available";
149+
}
150+
String Resultant=" ";
151+
Resultant =Resultant+" "+this.book_id + "\t" + this.title + "\t" + this.author + "\t" + this.subject + "\t" + this.quantity + "\t" + status + "\n";
152+
return Resultant;
153+
}
154+
155+
}

Borrower.java

+182
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,182 @@
1+
/*
2+
* To change this license header, choose License Headers in Project Properties.
3+
* To change this template file, choose Tools | Templates
4+
* and open the template in the editor.
5+
*/
6+
package library;
7+
8+
import java.util.*;
9+
import java.io.*;
10+
11+
/**
12+
*
13+
* @author Minahil Imtiaz
14+
*/
15+
public class Borrower extends Users {
16+
17+
private String address;
18+
private String telephone;
19+
private boolean fine_defaulter;
20+
private double fine;
21+
private ArrayList<Loan> BookLoans;
22+
23+
Borrower() {
24+
super();
25+
fine_defaulter = false;
26+
BookLoans = null;
27+
fine = 0.0;
28+
address = " ";
29+
telephone = " ";
30+
BookLoans = new ArrayList<>();
31+
32+
}
33+
34+
Borrower(int user_id, String user_name, char gender, String telephone, String address, boolean fine_defaulter, double fine) {
35+
super(user_id, user_name, gender);
36+
this.fine_defaulter = fine_defaulter;
37+
this.fine = fine;
38+
this.address = address;
39+
this.telephone = telephone;
40+
BookLoans = new ArrayList<>();
41+
42+
}
43+
44+
@Override
45+
public boolean GetFineStatus() {
46+
// return this.fine_defaulter;
47+
dbConnectivity db = new dbConnectivity();
48+
return (db.GetFineStatus(this.GetId()));
49+
}
50+
51+
public double GetFineAmout() {
52+
// return this.fine;
53+
dbConnectivity db = new dbConnectivity();
54+
return (db.GetFineAmount(this.GetId()));
55+
56+
}
57+
58+
public String GetAddress() {
59+
return this.address;
60+
61+
}
62+
63+
public String GetTelephone() {
64+
65+
return this.telephone;
66+
}
67+
68+
@Override
69+
public boolean SetFineStatus(boolean fine_defaulter) {
70+
this.fine_defaulter = fine_defaulter;
71+
dbConnectivity db = new dbConnectivity();
72+
boolean result = db.SetFineStatus(this.GetId(), fine_defaulter);
73+
return result;
74+
}
75+
76+
public boolean SetTelephone(String Telephone) {
77+
this.telephone = Telephone;
78+
dbConnectivity db = new dbConnectivity();
79+
boolean result = db.SetTelephone(this.GetId(), this.telephone);
80+
return result;
81+
82+
}
83+
84+
85+
public boolean SetAddress(String Address) {
86+
this.address = Address;
87+
dbConnectivity db = new dbConnectivity();
88+
boolean result = db.SetAddress(this.GetId(), this.address);
89+
return result;
90+
91+
}
92+
93+
@Override
94+
public void SetFineAmount(double user_fine) {
95+
this.fine = user_fine;
96+
dbConnectivity db = new dbConnectivity();
97+
boolean result = db.SetFineAmount(this.GetId(), user_fine);
98+
99+
100+
}
101+
102+
public void SetName(String name)
103+
{
104+
super.SetName(name);
105+
dbConnectivity db = new dbConnectivity();
106+
boolean result = db.SetName(this.GetId(), name);
107+
108+
}
109+
110+
111+
public void SetGender(char g)
112+
{
113+
super.SetGender(g);
114+
dbConnectivity db = new dbConnectivity();
115+
boolean result = db.SetGender(this.GetId(), g);
116+
117+
}
118+
119+
@Override
120+
public boolean AddLoanInfo(Loan LoanInfo) {
121+
122+
BookLoans.add(LoanInfo);
123+
return true;
124+
// dbConnectivity db = new dbConnectivity ();
125+
// boolean result=db.AddLoanInfo(this.GetId(), LoanInfo);
126+
// return result;
127+
128+
}
129+
130+
public void AllLoansofUser(ArrayList<Loan> LoansofUser) {
131+
132+
// this.BookLoans=LoansofUser;
133+
dbConnectivity db = new dbConnectivity();
134+
this.BookLoans = db.LoadLoanListofSpecificUser(this.GetId());
135+
}
136+
137+
//helping function to update loan info
138+
@Override
139+
public void UpdateLoanInfo(Loan Update, int book_id) {
140+
141+
// Iterator<Loan> itr = BookLoans.Iterator(BookLoans.size());
142+
// while (itr.hasPrevious()) {
143+
//
144+
// Loan L = itr.previous();
145+
for (int counter=BookLoans.size()-1 ; counter >=0; counter--){
146+
Loan L = BookLoans.get(counter);
147+
148+
if ((L.GetaBookId() == book_id)) {
149+
L.SetLoan(Update);
150+
break;
151+
}
152+
}
153+
154+
}
155+
156+
//needed to be checked
157+
@Override
158+
public String ViewInformation(ArrayList<Loan> LoanList, int user_id) {
159+
160+
161+
String Resultant="";
162+
Resultant=Resultant+super.PrintInformation();
163+
Resultant+="Adress :" + address+" ";
164+
Resultant+="Telephone:" + telephone+" ";
165+
Resultant+="\n Loan Info \n";
166+
167+
if (BookLoans.isEmpty() == false) {
168+
for (int i=0;i< BookLoans.size();i++) {
169+
Loan L=BookLoans.get(i);
170+
Resultant+=L.PrintLoanInfo();
171+
Resultant+="\n";
172+
}
173+
} else {
174+
175+
Resultant +="NO LOANS TILL YET!";
176+
}
177+
178+
return Resultant;
179+
180+
}
181+
182+
}

Clerk.java

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
/*
2+
* To change this license header, choose License Headers in Project Properties.
3+
* To change this template file, choose Tools | Templates
4+
* and open the template in the editor.
5+
*/
6+
package library;
7+
8+
/**
9+
*
10+
* @author Minahil Imtiaz
11+
*/
12+
public class Clerk extends Staff {
13+
14+
Clerk(int user_id, String user_name, char gender) {
15+
super(user_id, user_name, gender);
16+
}
17+
}

0 commit comments

Comments
 (0)