-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTransaction.java
More file actions
70 lines (60 loc) · 2.9 KB
/
Copy pathTransaction.java
File metadata and controls
70 lines (60 loc) · 2.9 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
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.time.temporal.ChronoUnit;
class Transaction {
private String transactionId;
private Member member;
private Book book;
private LocalDate borrowedDate;
private LocalDate estimatedReturnDate;
private LocalDate returnDate;
private String transactionStatus;
private final int DEFAULT_BORROW_DAYS = 7;
Transaction(String transactionId, Member member, Book book) {
this.transactionId = transactionId;
this.member = member;
this.book = book;
this.transactionStatus = "Pending";
}
public String getTransaction(){
//Implemented Using AI (Gemini Flash-Lite)
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("dd/MM/yyyy");
String borrowedDateString = (borrowedDate != null) ? borrowedDate.format(formatter) : "Not yet Borrowed";
String returnDateString = (returnDate != null) ? returnDate.format(formatter) : "Not yet Returned";
//Manual
return "Transaction ID : " + this.transactionId + "\nBook Title : " + this.book.getTitle() + "\nISBN : " + this.book.getISBN() + "\nMember ID : " + this.member.getUserId() + "\nName : " + this.member.getName() + "\nBorrowed Date : " + borrowedDateString + "\nReturned Date : " + returnDateString + "\nTransaction Status : " + this.transactionStatus;
}
public void borrowBook() {
this.borrowedDate = LocalDate.now();
this.estimatedReturnDate = this.borrowedDate.plusDays(DEFAULT_BORROW_DAYS);
this.transactionStatus = "Borrowed";
this.book.borrowed();
}
public void returnBook() {
this.returnDate = LocalDate.now();
this.transactionStatus = "Returned";
this.book.returned();
}
public long overdueDays(){
LocalDate dateToCompare = (returnDate != null) ? returnDate : LocalDate.now();
if (dateToCompare.isAfter(estimatedReturnDate)) {
return ChronoUnit.DAYS.between(estimatedReturnDate, dateToCompare);
}
return 0;
}
public String getTransactionId() { return this.transactionId; }
public Member getMember() { return this.member; }
public Book getBook() { return book; }
public String getTransactionStatus() { return transactionStatus; }
public LocalDate getBorrowedDate() { return borrowedDate; }
public LocalDate getEstimatedReturnDate() { return estimatedReturnDate; }
public LocalDate getReturnDate() { return returnDate; }
// START: Implemented using Antigravity AI (Gemini)
public void loadTransactionState(LocalDate borrowedDate, LocalDate estimatedReturnDate, LocalDate returnDate, String status) {
this.borrowedDate = borrowedDate;
this.estimatedReturnDate = estimatedReturnDate;
this.returnDate = returnDate;
this.transactionStatus = status;
}
// END: Implemented using Antigravity AI (Gemini)
}