-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMainApp.java
More file actions
63 lines (54 loc) · 2.24 KB
/
MainApp.java
File metadata and controls
63 lines (54 loc) · 2.24 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
import java.util.Scanner;
import java.util.List;
public class MainApp {
public static void main(String[] args) {
BookDAO dao = new BookDAO();
Scanner scanner = new Scanner(System.in);
while (true) {
System.out.println("Select an operation:");
System.out.println("1. Add Book");
System.out.println("2. List Books");
System.out.println("3. Update Book");
System.out.println("4. Delete Book");
System.out.println("5. Exit");
int choice = scanner.nextInt();
scanner.nextLine(); // Consume the newline
switch (choice) {
case 1:
System.out.print("Enter book name: ");
String name = scanner.nextLine();
System.out.print("Enter book ISBN: ");
String isbn = scanner.nextLine();
dao.addBook(new Book(0, name, isbn)); // ID 0 because it's auto-incremented in the DB
break;
case 2:
List<Book> books = dao.getAllBooks();
for (Book book : books) {
System.out.println(book);
}
break;
case 3:
System.out.print("Enter book ID to update: ");
int updateId = scanner.nextInt();
scanner.nextLine(); // Consume the newline
System.out.print("Enter new book name: ");
String newName = scanner.nextLine();
System.out.print("Enter new book ISBN: ");
String newIsbn = scanner.nextLine();
dao.updateBook(updateId, newName, newIsbn);
break;
case 4:
System.out.print("Enter book ID to delete: ");
int deleteId = scanner.nextInt();
dao.deleteBook(deleteId);
break;
case 5:
System.out.println("Exiting...");
System.exit(0);
break;
default:
System.out.println("Invalid choice. Try again.");
}
}
}
}