-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMain.java
More file actions
98 lines (84 loc) · 3.62 KB
/
Copy pathMain.java
File metadata and controls
98 lines (84 loc) · 3.62 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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("Welcome to the Library Management System");
System.out.println();
boolean state = true;
Library library = new Library(1000);
while (state) {
System.out.println("---- Menu ----");
System.out.println("1. Add Book");
System.out.println("2. View Books");
System.out.println("3. Borrow Book");
System.out.println("4. Search Book");
System.out.println("5. Remove Book");
System.out.println("6. Return Book");
System.out.println("7. Exit");
System.out.println();
System.out.println("Enter your choice (only numbers)");
int choice = sc.nextInt();
switch (choice) {
case 1:
System.out.println("--Add Book--");
System.out.println("Enter Book ID");
int id = sc.nextInt();
sc.nextLine();
System.out.println("Enter Book Title");
String title = sc.nextLine();
System.out.println("Enter Book Author");
String author = sc.nextLine();
System.out.println("Enter Book Available (true/false");
boolean available = sc.nextBoolean();
Book book = new Book(id, title, author, available);
library.addBook(book);
System.out.println("Book added successfully");
System.out.println("===========");
break;
case 2:
System.out.println("--View Books--");
library.showBook();
break;
case 3:
System.out.println("--Borrow Book--");
System.out.println("Enter Book ID");
int borrowId = sc.nextInt();
sc.nextLine();
library.borrowBook(borrowId);
break;
case 4:
sc.nextLine();
System.out.println("--Search Book--");
System.out.println("Enter Book Title");
String searchTitle = sc.nextLine();
Book search = library.searchBook(searchTitle);
if (search != null) {
System.out.println(search);
}
else System.out.println("Not Found");
break;
case 5:
System.out.println("--Remove Book--");
System.out.println("Enter Book ID");
int removeBookId = sc.nextInt();
sc.nextLine();
library.removeBook(removeBookId);
break;
case 6:
System.out.println("--Return Book--");
System.out.println("Enter Book ID");
int returnBookId = sc.nextInt();
sc.nextLine();
System.out.println(library.returnBook(returnBookId));
break;
case 7:
System.out.println("Exit");
state = false;
break;
default:
System.out.println("Invalid choice");
break;
}
}
}
}