-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathBooks.java
155 lines (122 loc) · 4.08 KB
/
Books.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
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package library;
import java.util.*;
import java.io.*;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
/**
*
* @author Minahil Imtiaz
*/
public class Books {
private int book_id;
private String author;
private String title;
private String subject;
private int quantity; //a book may have more than one quantity
Books() {
this.book_id = -1;
this.author = " ";
this.title = " ";
this.subject = " ";
this.quantity = 0;
}
Books(int book_id, String author, String title, String subject, int quantity) {
this.book_id = book_id;
this.author = author;
this.title = title;
this.subject = subject;
this.quantity = quantity;
}
public void SetBookId(int book_id) {
this.book_id = book_id;
}
public void SetAuthor(String author) {
this.author = author;
dbConnectivity db = new dbConnectivity();
db.ChangeBookInfo(book_id, author, 2);
}
public void SetTitle(String title) {
this.title = title;
dbConnectivity db = new dbConnectivity();
db.ChangeBookInfo(book_id, title, 1);
}
public void SetQuantity(int quantity) {
this.quantity = quantity;
dbConnectivity db = new dbConnectivity();
db.UpdateBookQuantity(this.quantity, this.book_id);
}
public void SetSubject(String subject) {
this.subject = subject;
dbConnectivity db = new dbConnectivity();
db.ChangeBookInfo(book_id, subject, 3);
}
public String GetTitle() {
dbConnectivity db = new dbConnectivity();
String titleofbook = db.GetTitleofBook(this.book_id);
return titleofbook;
}
public String GetAuthor() {
dbConnectivity db = new dbConnectivity();
String authorofbook = db.GetAuthorofBook(this.book_id);
return authorofbook;
}
public int GetBookId() {
return this.book_id;
}
public String GetSubject() {
dbConnectivity db = new dbConnectivity();
String subjectofbook = db.GetSubjectofBook(this.book_id);
return subjectofbook;
// return this.subject;
}
public Books GetaBook() {
dbConnectivity db = new dbConnectivity();
Books MyBook = db.GetaBookbyId(this.book_id);
return MyBook;
}
public int GetQuantity() {
dbConnectivity db = new dbConnectivity();
int quantity_available = db.GetQuantityofBook(this.book_id);
// return this.quantity;
return quantity_available;
}
public boolean ChekcAvailability(int book_id) {
dbConnectivity db = new dbConnectivity();
int quantity_available = db.GetQuantityofBook(this.book_id);
if (quantity_available <= 0) {
return false;
} else {
return true;
}
}
public void DecreaseQuantity() {
if (quantity > 0) {
this.quantity = this.quantity - 1;
dbConnectivity db = new dbConnectivity();
db.UpdateBookQuantity(this.quantity, book_id);
}
}
public void IncreaseQuantity() {
this.quantity = this.quantity + 1;
dbConnectivity db = new dbConnectivity();
db.UpdateBookQuantity(this.quantity, book_id);
}
public String PrintInformation() {
boolean available = ChekcAvailability(this.book_id);
String status;
if (available == true) {
status = "available";
} else {
status = "not available";
}
String Resultant=" ";
Resultant =Resultant+" "+this.book_id + "\t" + this.title + "\t" + this.author + "\t" + this.subject + "\t" + this.quantity + "\t" + status + "\n";
return Resultant;
}
}