Skip to content

Commit 27fe9db

Browse files
committed
Added Library catalog system
1 parent e918b31 commit 27fe9db

File tree

1 file changed

+81
-0
lines changed

1 file changed

+81
-0
lines changed

Library Catalog System.java

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
import java.util.ArrayList;
2+
import java.util.Scanner;
3+
4+
class Book {
5+
private String title;
6+
private String author;
7+
private String isbn;
8+
private String category;
9+
private boolean available;
10+
11+
public Book(String title, String author, String isbn, String category) {
12+
this.title = title;
13+
this.author = author;
14+
this.isbn = isbn;
15+
this.category = category;
16+
this.available = true;
17+
}
18+
19+
// Getters and setters for book details
20+
21+
public boolean isAvailable() {
22+
return available;
23+
}
24+
25+
public void checkOut() {
26+
available = false;
27+
}
28+
29+
public void returnBook() {
30+
available = true;
31+
}
32+
}
33+
34+
public class LibraryCatalogSystem {
35+
private static ArrayList<Book> catalog = new ArrayList<>();
36+
private static Scanner scanner = new Scanner(System.in);
37+
38+
public static void main(String[] args) {
39+
while (true) {
40+
displayMenu();
41+
int choice = scanner.nextInt();
42+
scanner.nextLine(); // Consume newline character
43+
44+
switch (choice) {
45+
case 1:
46+
addBook();
47+
break;
48+
case 2:
49+
searchBooks();
50+
break;
51+
case 3:
52+
viewBookDetails();
53+
break;
54+
case 4:
55+
checkoutBook();
56+
break;
57+
case 5:
58+
returnBook();
59+
break;
60+
case 6:
61+
System.out.println("Goodbye!");
62+
System.exit(0);
63+
default:
64+
System.out.println("Invalid choice. Please try again.");
65+
}
66+
}
67+
}
68+
69+
// Implement methods for adding, searching, viewing, checking out, and returning books
70+
71+
private static void displayMenu() {
72+
System.out.println("\nLibrary Catalog System");
73+
System.out.println("1. Add a new book");
74+
System.out.println("2. Search books");
75+
System.out.println("3. View book details");
76+
System.out.println("4. Checkout a book");
77+
System.out.println("5. Return a book");
78+
System.out.println("6. Exit");
79+
System.out.print("Enter your choice: ");
80+
}
81+
}

0 commit comments

Comments
 (0)