-
Notifications
You must be signed in to change notification settings - Fork 8
/
LibraryClass.java
55 lines (46 loc) · 1.26 KB
/
LibraryClass.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
import java.util.ArrayList;
/**
*
* @author giuseppedesantis
*/
public class Library {
private ArrayList<Book> books;
public Library(){
this.books = new ArrayList<Book>();
}
public void addBook(Book newBook){
this.books.add(newBook);
}
public void printBooks(){
for(Book b : this.books){
System.out.println(b);
}
}
public ArrayList<Book> searchByTitle(String title){
ArrayList<Book> found = new ArrayList<Book>();
for(Book b : this.books){
if(StringUtils.included(b.title(), title)){
found.add(b);
}
}
return found;
}
public ArrayList<Book> searchByPublisher(String publisher){
ArrayList<Book> found = new ArrayList<Book>();
for(Book b : this.books){
if(StringUtils.included(b.publisher(), publisher)){
found.add(b);
}
}
return found;
}
public ArrayList<Book> searchByYear(int year){
ArrayList<Book> found = new ArrayList<Book>();
for(Book b : this.books){
if(b.year() == year){
found.add(b);
}
}
return found;
}
}