diff --git a/src b/src new file mode 100644 index 0000000..eead080 --- /dev/null +++ b/src @@ -0,0 +1,47 @@ +import java.util.Scanner; + +// 主类 +public class Main { + public static void main(String[] args) { + BookManagementSystem bms = new BookManagementSystem(); + Scanner scanner = new Scanner(System.in); + + while (true) { + System.out.println("\n图书管理系统"); + System.out.println("1. 添加图书"); + System.out.println("2. 显示图书列表"); + System.out.println("3. 查找图书"); + System.out.println("4. 退出"); + System.out.print("请输入选项:"); + + int choice = scanner.nextInt(); + scanner.nextLine(); // 消耗换行符 + + switch (choice) { + case 1: + System.out.print("请输入图书ID:"); + String id = scanner.nextLine(); + System.out.print("请输入图书名称:"); + String name = scanner.nextLine(); + System.out.print("请输入图书作者:"); + String author = scanner.nextLine(); + bms.addBook(id, name, author); + break; + case 2: + bms.displayBooks(); + break; + case 3: + System.out.print("请输入查找关键词:"); + String keyword = scanner.nextLine(); + bms.searchBook(keyword); + break; + case 4: + System.out.println("感谢使用图书管理系统,再见!"); + scanner.close(); + return; + default: + System.out.println("无效选项,请重新输入!"); + } + } + } +} \ No newline at end of file