FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
Java-Library-Management-Pro/Member.java at main · Wadan3/Java-Library-Management-Pro · GitHub
Wadan3
/
Java-Library-Management-Pro
Public
Notifications
You must be signed in to change notification settings
Fork
0
Star
23
Code
Issues
0
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
Java-Library-Management-Pro
/
Member.java
Copy path
More file actions
More file actions
Latest commit
History
History
History
56 lines (48 loc) · 1.55 KB
Breadcrumbs
Java-Library-Management-Pro
/
Member.java
Copy path
File metadata and controls
56 lines (48 loc) · 1.55 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
import
java
.
util
.
ArrayList
;
import
java
.
util
.
List
;
class
Member
{
private
String
memberId
;
private
String
name
;
private
List
<
Book
>
borrowedBooks
;
public
Member
(
String
memberId
,
String
name
) {
if
(
memberId
.
length
() !=
6
) {
throw
new
IllegalArgumentException
(
"Member ID must be exactly 6 characters long."
);
}
this
.
memberId
=
memberId
;
this
.
name
=
name
;
this
.
borrowedBooks
=
new
ArrayList
<>();
}
public
String
getMemberId
() {
return
memberId
;
}
public
String
getName
() {
return
name
;
}
public
void
borrowBook
(
Book
book
) {
if
(
borrowedBooks
.
size
() <
3
&&
book
.
isAvailable
()) {
borrowedBooks
.
add
(
book
);
book
.
borrow
();
}
else
{
throw
new
IllegalStateException
(
"Cannot borrow book: either limit reached or book not available."
);
}
}
public
void
returnBook
(
Book
book
) {
if
(
borrowedBooks
.
contains
(
book
)) {
borrowedBooks
.
remove
(
book
);
book
.
returnBook
();
}
else
{
throw
new
IllegalArgumentException
(
"This book was not borrowed by the member."
);
}
}
public
void
printMemberInfo
() {
System
.
out
.
print
(
"Member ID: "
+
memberId
+
", Name: "
+
name
+
", Borrowed Books: "
);
if
(
borrowedBooks
.
isEmpty
()) {
System
.
out
.
println
(
"None"
);
}
else
{
for
(
Book
book
:
borrowedBooks
) {
System
.
out
.
print
(
book
.
getTitle
() +
" "
);
}
System
.
out
.
println
();
}
}
}
Back
|
FazBrowse Home
|
New Git URL