-
Notifications
You must be signed in to change notification settings - Fork 0
/
User.java
45 lines (35 loc) · 954 Bytes
/
User.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
import java.time.LocalDate;
import java.time.Period;
import java.util.ArrayList;
public class User {
private String name;
private LocalDate birthDay;
private ArrayList<Book> books = new ArrayList<Book>();
// Constructor
User(String name, String birthDay) {
this.name = name;
this.birthDay = LocalDate.parse(birthDay);
}
public String getName() {
return this.name;
}
public String getBirthDay() {
return this.birthDay.toString();
}
public String borrowedBooks() {
return this.books.toString();
}
public void setName(String name) {
this.name = name;
}
public void setBirthDay(LocalDate birthDay) {
this.birthDay = birthDay;
}
public void borrow(Book book) {
this.books.add(book);
}
public int age() {
int age = Period.between(this.birthDay, LocalDate.now()).getYears();
return age;
}
}