-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathIssuedBook.java
More file actions
264 lines (224 loc) · 7.63 KB
/
Copy pathIssuedBook.java
File metadata and controls
264 lines (224 loc) · 7.63 KB
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
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
package models;
import java.io.Serializable;
import java.time.LocalDate;
import java.util.Objects;
/**
* IssuedBook.java - Transaction record for book issues and returns
*
* Purpose: Track when books are issued and returned
* Maintains:
* - Issue and due dates
* - Return status
* - Member information
*/
public class IssuedBook implements Serializable {
private static final long serialVersionUID = 1L;
// Transaction identifiers
private int issueId; // Unique transaction ID
private int bookId; // Foreign key to books table
private String bookTitle; // Denormalized for display
// Date information
private LocalDate issuedDate; // Date book was issued
private LocalDate dueDate; // Expected return date
private LocalDate returnDate; // Actual return date (null if not returned)
// Status and member info
private String status; // "ISSUED" or "RETURNED"
private String memberName; // Who issued the book
private String memberContact; // Phone/email for follow-up
// Constants
public static final String STATUS_ISSUED = "ISSUED";
public static final String STATUS_RETURNED = "RETURNED";
private static final int DEFAULT_ISSUE_DAYS = 14; // 2 weeks
// Constructors
/**
* No-argument constructor for framework compatibility
*/
public IssuedBook() {
this.status = STATUS_ISSUED;
}
/**
* Constructor for new issue (issueId is auto-generated)
*/
public IssuedBook(int bookId, String bookTitle, LocalDate issuedDate,
int issueDays, String memberName, String memberContact) {
this.bookId = bookId;
this.bookTitle = bookTitle;
this.issuedDate = issuedDate;
this.dueDate = issuedDate.plusDays(issueDays);
this.returnDate = null;
this.status = STATUS_ISSUED;
this.memberName = memberName;
this.memberContact = memberContact;
}
/**
* Full constructor with all fields
*/
public IssuedBook(int issueId, int bookId, String bookTitle,
LocalDate issuedDate, LocalDate dueDate,
LocalDate returnDate, String status,
String memberName, String memberContact) {
this.issueId = issueId;
this.bookId = bookId;
this.bookTitle = bookTitle;
this.issuedDate = issuedDate;
this.dueDate = dueDate;
this.returnDate = returnDate;
this.status = status;
this.memberName = memberName;
this.memberContact = memberContact;
}
// Getters and Setters (Encapsulation)
public int getIssueId() {
return issueId;
}
public void setIssueId(int issueId) {
if (issueId < 0) {
throw new IllegalArgumentException("Issue ID must be positive");
}
this.issueId = issueId;
}
public int getBookId() {
return bookId;
}
public void setBookId(int bookId) {
if (bookId <= 0) {
throw new IllegalArgumentException("Book ID must be positive");
}
this.bookId = bookId;
}
public String getBookTitle() {
return bookTitle;
}
public void setBookTitle(String bookTitle) {
if (bookTitle == null || bookTitle.trim().isEmpty()) {
throw new IllegalArgumentException("Book title cannot be empty");
}
this.bookTitle = bookTitle;
}
public LocalDate getIssuedDate() {
return issuedDate;
}
public void setIssuedDate(LocalDate issuedDate) {
if (issuedDate == null || issuedDate.isAfter(LocalDate.now())) {
throw new IllegalArgumentException("Issued date cannot be in future");
}
this.issuedDate = issuedDate;
}
public LocalDate getDueDate() {
return dueDate;
}
public void setDueDate(LocalDate dueDate) {
if (dueDate == null) {
throw new IllegalArgumentException("Due date cannot be null");
}
this.dueDate = dueDate;
}
public LocalDate getReturnDate() {
return returnDate;
}
public void setReturnDate(LocalDate returnDate) {
if (returnDate != null && returnDate.isAfter(LocalDate.now())) {
throw new IllegalArgumentException("Return date cannot be in future");
}
if (returnDate != null && returnDate.isBefore(issuedDate)) {
throw new IllegalArgumentException("Return date cannot be before issue date");
}
this.returnDate = returnDate;
}
public String getStatus() {
return status;
}
public void setStatus(String status) {
if (!status.equals(STATUS_ISSUED) && !status.equals(STATUS_RETURNED)) {
throw new IllegalArgumentException("Status must be ISSUED or RETURNED");
}
this.status = status;
}
public String getMemberName() {
return memberName;
}
public void setMemberName(String memberName) {
if (memberName == null || memberName.trim().isEmpty()) {
throw new IllegalArgumentException("Member name cannot be empty");
}
this.memberName = memberName;
}
public String getMemberContact() {
return memberContact;
}
public void setMemberContact(String memberContact) {
this.memberContact = memberContact != null ? memberContact : "";
}
// Business Logic Methods
/**
* Marks book as returned
* Called when member returns the book
*/
public void markAsReturned() {
this.returnDate = LocalDate.now();
this.status = STATUS_RETURNED;
}
/**
* Checks if book is overdue
*
* @return true if current date > due date and not returned
*/
public boolean isOverdue() {
return status.equals(STATUS_ISSUED) && LocalDate.now().isAfter(dueDate);
}
/**
* Gets days overdue
*
* @return number of days overdue, 0 if not overdue
*/
public long getDaysOverdue() {
if (!isOverdue()) {
return 0;
}
return java.time.temporal.ChronoUnit.DAYS.between(dueDate, LocalDate.now());
}
/**
* Gets fine amount based on overdue days
* Example: ₹5 per day after due date
*
* @return fine amount in rupees
*/
public double calculateFine() {
long overdueDay = getDaysOverdue();
return overdueDay > 0 ? overdueDay * 5.0 : 0.0;
}
/**
* Checks if book is currently issued (not returned)
*
* @return true if status is ISSUED
*/
public boolean isCurrentlyIssued() {
return status.equals(STATUS_ISSUED);
}
// Object Methods
@Override
public String toString() {
return "IssuedBook{" +
"issueId=" + issueId +
", bookId=" + bookId +
", bookTitle='" + bookTitle + '\'' +
", issuedDate=" + issuedDate +
", dueDate=" + dueDate +
", returnDate=" + returnDate +
", status='" + status + '\'' +
", memberName='" + memberName + '\'' +
", memberContact='" + memberContact + '\'' +
'}';
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
IssuedBook that = (IssuedBook) o;
return issueId == that.issueId;
}
@Override
public int hashCode() {
return Objects.hash(issueId);
}
}