-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLMSMain.java
More file actions
139 lines (110 loc) · 5.14 KB
/
Copy pathLMSMain.java
File metadata and controls
139 lines (110 loc) · 5.14 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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
package LMS.com;
import java.sql.Connection;
import java.sql.SQLException;
import java.util.Scanner;
public class LMSMain {
public static void main(String[] args) {
try (Connection connection = dbconnection.getConnection();
Scanner sc = new Scanner(System.in)) {
Members members = new Members();
LibraryService services = new LibraryService();
Transaction transactions = new Transaction();
ReturnBook returnBook = new ReturnBook();
// Books books = new Books();
// IssueBook issueBook = new IssueBook();
while (true) {
System.out.println("\n══════════════════════════════════");
System.out.println("📚 LIBRARY MANAGEMENT SYSTEM");
System.out.println("══════════════════════════════════");
System.out.println("1️⃣ Member Management");
System.out.println("2️⃣ Library Services");
System.out.println("3️⃣ Transactions");
System.out.println("4️⃣ Return Book");
System.out.println("0️⃣ Exit");
System.out.print("👉 Select Option: ");
int choice = sc.nextInt();
switch (choice) {
case 1 -> memberMenu(members, connection, sc);
case 2 -> serviceMenu(services, connection, sc);
case 3 -> transactionMenu(transactions, connection, sc);
case 4 -> returnMenu(returnBook, connection, sc);
case 0 -> {
System.out.println("👋 Thank you for using LMS!");
return;
}
default -> System.out.println("❌ Invalid Option! Try again.");
}
}
} catch (SQLException e) {
System.out.println("⚠ Database Connection Error: " + e.getMessage());
}
}
// ================= MEMBER MENU =================
private static void memberMenu(Members members, Connection con, Scanner sc) throws SQLException {
System.out.println("\n👥 MEMBER MANAGEMENT");
System.out.println("1. Add Member");
System.out.println("2. Update Member");
System.out.println("3. Delete Member");
System.out.println("4. View Members");
System.out.print("Choose: ");
int ch = sc.nextInt();
switch (ch) {
case 1 -> members.insert(con);
case 2 -> members.update(con);
case 3 -> members.delete(con);
case 4 -> members.getAll(con);
default -> System.out.println("❌ Invalid Choice");
}
}
// ================= SERVICE MENU =================
private static void serviceMenu(LibraryService service, Connection con, Scanner sc) throws SQLException {
System.out.println("\n📚 LIBRARY SERVICES");
System.out.println("1. Add Service");
System.out.println("2. Update Service");
System.out.println("3. Delete Service");
System.out.println("4. View Services");
System.out.print("Choose: ");
int ch = sc.nextInt();
switch (ch) {
case 1 -> service.insert(con);
case 2 -> service.update(con);
case 3 -> service.delete(con);
case 4 -> service.getAll(con);
default -> System.out.println("❌ Invalid Choice");
}
}
// ================= TRANSACTION MENU =================
private static void transactionMenu(Transaction txn, Connection con, Scanner sc) throws SQLException {
System.out.println("\n📑 TRANSACTIONS");
System.out.println("1. Add Transaction");
System.out.println("2. Update Transaction");
System.out.println("3. Delete Transaction");
System.out.println("4. View Transactions");
System.out.print("Choose: ");
int ch = sc.nextInt();
switch (ch) {
case 1 -> txn.insert(con);
case 2 -> txn.update(con);
case 3 -> txn.delete(con);
case 4 -> txn.getAll(con);
default -> System.out.println("❌ Invalid Choice");
}
}
// ================= RETURN MENU =================
private static void returnMenu(ReturnBook rb, Connection con, Scanner sc) throws SQLException {
System.out.println("\n🔄 RETURN BOOK");
System.out.println("1. Add Return");
System.out.println("2. Update Return");
System.out.println("3. Delete Return");
System.out.println("4. View Returns");
System.out.print("Choose: ");
int ch = sc.nextInt();
switch (ch) {
case 1 -> rb.insert(con);
case 2 -> rb.update(con);
case 3 -> rb.delete(con);
case 4 -> rb.getAll(con);
default -> System.out.println("❌ Invalid Choice");
}
}
}