-
Notifications
You must be signed in to change notification settings - Fork 0
/
Lending.java
151 lines (119 loc) · 3.63 KB
/
Lending.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
public class Lending {
private int id, bookId, memberId;
private int due_day, due_month, due_year;
private int lend_day, lend_month, lend_year;
private int return_day, return_month, return_year;
// Constructor
public Lending(int id, int bookId, int memberId, int due_day, int due_month, int due_year, int lend_day,
int lend_month, int lend_year, int return_day, int return_month, int return_year) {
this.id = id;
this.bookId = bookId;
this.memberId = memberId;
this.due_day = due_day;
this.due_month = due_month;
this.due_year = due_year;
this.lend_day = lend_day;
this.lend_month = lend_month;
this.lend_year = lend_year;
this.return_day = return_day;
this.return_month = return_month;
this.return_year = return_year;
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public int getBookId() {
return bookId;
}
public void setBookId(int bookId) {
this.bookId = bookId;
}
public int getMemberId() {
return memberId;
}
public void setMemberId(int memberId) {
this.memberId = memberId;
}
public int getDue_day() {
return due_day;
}
public void setDue_day(int due_day) {
this.due_day = due_day;
}
public int getDue_month() {
return due_month;
}
public void setDue_month(int due_month) {
this.due_month = due_month;
}
public int getDue_year() {
return due_year;
}
public void setDue_year(int due_year) {
this.due_year = due_year;
}
public int getLend_day() {
return lend_day;
}
public void setLend_day(int lend_day) {
this.lend_day = lend_day;
}
public int getLend_month() {
return lend_month;
}
public void setLend_month(int lend_month) {
this.lend_month = lend_month;
}
public int getLend_year() {
return lend_year;
}
public void setLend_year(int lend_year) {
this.lend_year = lend_year;
}
public int getReturn_day() {
return return_day;
}
public void setReturn_day(int return_day) {
this.return_day = return_day;
}
public int getReturn_month() {
return return_month;
}
public void setReturn_month(int return_month) {
this.return_month = return_month;
}
public int getReturn_year() {
return return_year;
}
public void setReturn_year(int return_year) {
this.return_year = return_year;
}
public double calculateFine(int returnedDay, int returnedMonth, int returnedYear) {
// 50 per additional day for up to 7 days
// 100 per additional day after 7 days
// Calculate overdue period
int overdue_days = 0;
overdue_days += (returnedYear - this.getDue_year()) * 365;
overdue_days += (returnedMonth - this.getDue_month()) * 30;
overdue_days += (returnedDay - this.getDue_day());
// Calculate fine
double fine = 0;
if (overdue_days <= 7) {
fine = overdue_days * 50;
} else {
fine = 7 * 50 + (overdue_days - 7) * 100;
}
return fine;
}
public int overdueDays(int returnedDay, int returnedMonth, int returnedYear) {
// Calculate overdue period
int overdueDays = 0;
overdueDays += (returnedYear - this.getDue_year()) * 365;
overdueDays += (returnedMonth - this.getDue_month()) * 30;
overdueDays += (returnedDay - this.getDue_day());
return overdueDays;
}
}