-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMember.java
239 lines (211 loc) · 7.09 KB
/
Member.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
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
package library_management;
import java.util.InputMismatchException;
import java.util.Scanner;
import java.util.Vector;
public class Member
{
String name ;
String phone ;
int member_id ;
int fine ;
int age ;
Vector<Book> books_issued_id ;
Member(String name, String phone, int member_id, int age)
{
this.name = name ;
this.phone = phone ;
this.member_id = member_id ;
this.books_issued_id = new Vector<Book>() ;
this.fine = 0 ;
this.age = age ;
}
public void issueBook(Vector<Book> List_Books)
{
if (this.fine != 0)
{
System.out.println("Clear your fine to issue a book.") ;
return ;
}
if (this.books_issued_id.size() == 2)
{
System.out.println("You have already issued 2 books. Return a book to issue another one.") ;
return ;
}
else if (this.books_issued_id.size() == 1)
{
long currentTimeMillis = System.currentTimeMillis() ;
long currentTimeSeconds = currentTimeMillis / 1000 ;
if (currentTimeSeconds - this.books_issued_id.get(0).status > 10)
{
System.out.println("Return the book you have issued first, and clear your fine to issue another book.") ;
return ;
}
else
{
Scanner sc = new Scanner(System.in) ;
System.out.print("Book ID: ") ;
int book_id ;
while (true)
{
try
{
book_id = sc.nextInt() ;
break ;
}
catch (InputMismatchException e)
{
System.out.println("Invalid Book ID. Please enter an integer.") ;
sc.nextLine() ;
}
}
sc.nextLine() ;
System.out.print("Book Name: ") ;
String book_name = sc.nextLine() ;
for (Book listBook : List_Books)
{
if (listBook.book_id == book_id && listBook.title.equals(book_name) && listBook.status == 0)
{
List_Books.remove(listBook) ;
listBook.status = (int) currentTimeSeconds ;
this.books_issued_id.add(listBook) ;
System.out.println("Book issued successfully!") ;
List_Books.add(listBook) ;
return ;
}
}
System.out.println("Book not found!") ;
}
}
else
{
long currentTimeMillis = System.currentTimeMillis() ;
long currentTimeSeconds = currentTimeMillis / 1000 ;
Scanner sc = new Scanner(System.in) ;
System.out.print("Book ID: ") ;
int book_id ;
while (true)
{
try
{
book_id = sc.nextInt() ;
break ;
}
catch (InputMismatchException e)
{
System.out.println("Invalid Book ID. Please enter an integer.") ;
sc.nextLine() ;
}
}
sc.nextLine() ;
System.out.print("Book Name: ") ;
String book_name = sc.nextLine() ;
for (Book listBook : List_Books)
{
if (listBook.book_id == book_id && listBook.title.equals(book_name) && listBook.status == 0)
{
List_Books.remove(listBook) ;
listBook.status = (int) currentTimeSeconds ;
this.books_issued_id.add(listBook) ;
System.out.println("Book issued successfully!") ;
List_Books.add(listBook) ;
return ;
}
}
System.out.println("Book not found!") ;
}
}
public void returnBook(Vector<Book> List_Books)
{
if (this.books_issued_id.isEmpty())
{
System.out.println("You have not issued any books!") ;
return ;
}
else
{
Scanner sc = new Scanner(System.in) ;
System.out.print("Book ID: ") ;
int book_id ;
while (true)
{
try
{
book_id = sc.nextInt() ;
break ;
}
catch (InputMismatchException e)
{
System.out.println("Invalid choice. Please enter an integer.") ;
sc.nextLine() ;
}
}
sc.nextLine() ;
long currentTimeMillis = System.currentTimeMillis() ;
long currentTimeSeconds = currentTimeMillis / 1000 ;
int fl = 0 ;
Book to_return = new Book("", "", 0) ;
for (Book is_it : this.books_issued_id)
{
if (is_it.book_id == book_id)
{
to_return = is_it ;
this.books_issued_id.remove(is_it) ;
int time_gap = (int) (currentTimeSeconds - is_it.status) ;
if (time_gap > 10)
{
this.fine = (time_gap - 10) * 3 ;
System.out.println("Book returned successfully! " + this.fine + " rupees fine has been charged for a delay of " + (time_gap - 10) + " days.") ;
}
fl = 1 ;
break ;
}
}
if (fl == 0)
{
System.out.println("You have not issued this book!") ;
return ;
}
for (Book is_it : List_Books)
{
if (is_it == to_return)
{
List_Books.remove(is_it) ;
is_it.status = 0 ;
List_Books.add(is_it) ;
return ;
}
}
}
}
public void listMyBooks()
{
if (this.books_issued_id.isEmpty())
{
System.out.println("You have not issued any books!") ;
return ;
}
else
{
System.out.println("Books issued by you are: ") ;
for (Book is_it : this.books_issued_id)
{
System.out.println("Book Title: " + is_it.title) ;
System.out.println("Book Author: " + is_it.author) ;
System.out.println("Book ID: " + is_it.book_id) ;
System.out.println() ;
}
}
}
public void payFine()
{
if (this.fine == 0)
{
System.out.println("You have no fine to pay!") ;
}
else
{
System.out.println("You had a total fine of Rs." + this.fine + " .It has been paid successfully!") ;
this.fine = 0 ;
}
}
}