-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBookSearching.java
More file actions
45 lines (39 loc) · 1.25 KB
/
BookSearching.java
File metadata and controls
45 lines (39 loc) · 1.25 KB
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.util.Vector;
public class BookSearching {
private int choice;
private String searchKey;
private Vector<Book> bookList;
private Vector<Book> searchResults;
public BookSearching(int choice, String searchKey, Vector<Book> bookList) {
this.choice = choice;
this.searchKey = searchKey;
this.bookList = bookList;
this.searchResults = new Vector<>();
if (choice == 1) {
this.searchResults = searchByTitle(searchKey);
} else if (choice == 2) {
this.searchResults = searchByID(searchKey);
}
}
public Vector<Book> searchByTitle(String title) {
Vector<Book> result = new Vector<>();
for (Book book : bookList) {
if (book.getTitle().toLowerCase().contains(title.toLowerCase())) {
result.add(book);
}
}
return result;
}
public Vector<Book> searchByID(String id) {
Vector<Book> result = new Vector<>();
for (Book book : bookList) {
if (book.getBookId().toLowerCase().equals(id.toLowerCase())) {
result.add(book);
}
}
return result;
}
public Vector<Book> getSearchResults() {
return searchResults;
}
}