package booksystem;
import java.util.*;
public class BookSystem {
String book[]={"平凡的世界","高等数学","C程序设计"};
Scanner input=new Scanner(System.in);
public static void main(String[] args) {
BookSystem begin=new BookSystem();
begin.welcome();
}
public void welcome(){
System.out.println("输入命令:1-按照名称查找图书;2-按照序号查找图书;");
try{
int select=input.nextInt();
if(select==1)
this.searchName();
else if(select==2)
this.searchNum();
else throw new Exception();
}catch(Exception e){
System.out.println("请输入正确的指令");
input.nextLine(); //跳过错误类型
this.welcome();
}
}
public void searchName(){
System.out.println("请输入图书名称:");
String bookname=input.next();
System.out.println(bookname);
Boolean flag=false;
for(int i=0;i<book.length;i++)
if(bookname.equals(book[i]))
flag=true;
if(flag)
System.out.println("图书:"+bookname);
else System.out.println("图书不存在");
this.welcome();
}
public void searchNum(){
System.out.println("请输入图书序号:");
int num=input.nextInt();
if(num<=book.length)
System.out.println("图书:"+book[num-1]);
else System.out.println("图书不存在");
this.welcome();
}
}