-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLibrary.java
57 lines (47 loc) · 1.04 KB
/
Library.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
56
57
//EMP5117
//Winter 2019
//Assignment-2
public class Library {
Book[] books = null;
int bookPointer = 0;
public Library(int size){
books = new Book[size];
}
void addBook(Book book){
if(bookPointer == (books.length -1)){
System.out.println("The library is full");
}
else{
books[bookPointer] = book;
bookPointer++;
}
}
void printLibrary(){
for (int i = 0; i < books.length; i++) {
if(books[i] != null){
System.out.println(books[i].toString());
}
}
}
void searchAuthor(String author){
for (int i = 0; i < books.length; i++) {
if(books[i] != null && books[i].author.equals(author)){
System.out.println(books[i].toString());
}
}
}
void searchTitle(String title){
for (int i = 0; i < books.length; i++) {
if(books[i] != null && books[i].title.equals(title)){
System.out.println(books[i].toString());
}
}
}
void searchYear(int year){
for (int i = 0; i < books.length; i++) {
if(books[i] != null && books[i].year == year){
System.out.println(books[i].toString());
}
}
}
}