package com.imooc;
import java.util.Scanner;
public class Book {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
Book bk=new Book();
String[] bookName={"语文","数学","英语","物理","化学","生物"};
System.out.println("欢迎使用图书管理系统");
while(true){
System.out.println("请选择图书查询方式(0.退出):");
System.out.println("1.通过书名查询\t2.通过序号查询");
Scanner input=new Scanner(System.in);
try {
String name;
int sel=input.nextInt();
if(0==sel)
{ System.out.println("谢谢使用,再见!");
return;
}
switch(sel){
case 1:
System.out.println("请输入书名:");
name=bk.bookname(bookName);
System.out.println("已找到book:"+name);
break;
case 2:
System.out.println("请输入序号:");
name=bk.booknum(bookName);
System.out.println("已找到book:"+name);
break;
default:System.out.println("输入错误!");
}
} catch (Exception e) {
// TODO: handle exception
System.out.println("图书不存在!");
}
}
}
public String bookname(String[] book) throws Exception{
Scanner input=new Scanner(System.in);
String name=input.next();
for(int i=0;i<book.length;i++){
if(name.equals(book[i])){
return book[i];
}
}
throw new Exception("图书不存在!");
}
public String booknum(String[] book) throws Exception{
Scanner input=new Scanner(System.in);
int id=input.nextInt();
if(id>0 && id<=book.length){
return book[id-1];
}
throw new Exception("图书不存在!");
}
}