-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUser.java
More file actions
40 lines (37 loc) · 1015 Bytes
/
User.java
File metadata and controls
40 lines (37 loc) · 1015 Bytes
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
public class User {
protected String userId;
protected String name;
protected short maxBorrowLimit=1;
private Library_Item borrowedItem;
public User(String userId,String name){
this.userId=userId;
this.name=name;
this.borrowedItem=null;
}
protected void borrow(Library_Item item){
if(borrowedItem!=null){
System.out.println(name + "has already borrowed it." );
} else if (item.isAvailable) {
borrowedItem=item;
item.borrowItem();
}
}
protected void returnItem(){
if(borrowedItem==null){
System.out.println(name+" has not borrowed any book.");
}
else {
borrowedItem.returnItem();
borrowedItem=null;
}
}
protected void showBorrowedItems(){
if(borrowedItem==null){
System.out.println(name+" has not borrowed any book.");
}
else{
System.out.println(name+"has borrowed: ");
borrowedItem.displayDetails();
}
}
}