You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.
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 ( "无效选项,请重新输入!" ) ;
}
}
}
}