-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLibrary.java
45 lines (39 loc) · 1.26 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
import java.util.ArrayList;
import java.util.Scanner;
class Library {
private ArrayList<Book> books;
private Scanner scanner;
public Library() {
books = new ArrayList<>();
scanner = new Scanner(System.in);
}
public void addBook() {
System.out.print("Enter Book Title: ");
String title = scanner.nextLine();
System.out.print("Enter Author: ");
String author = scanner.nextLine();
System.out.print("Enter ISBN: ");
int ISBN = scanner.nextInt();
System.out.print("Enter Published Year: ");
int year = scanner.nextInt();
scanner.nextLine(); // Consume the newline character
books.add(new Book(title, author, ISBN, year));
}
public void displayBooks() {
for (Book book : books) {
book.displayBook();
System.out.println();
}
}
public void searchBook() {
System.out.print("Enter Title to search: ");
String title = scanner.nextLine();
for (Book book : books) {
if (book.title.equalsIgnoreCase(title)) {
book.displayBook();
return;
}
}
System.out.println("Book not found.");
}
}