package demo01book;
import java.util.Scanner;
public class Initail {
public static void main(String[] args) {
inputCommand();
}
public static void inputCommand(){
System.out.println("输入命令:1-按照名称查找图书;2-按照序号查找图书");
Scanner sc = new Scanner(System.in);
try{
int flag = sc.nextInt();
if(flag == 1){inputName();
}
if(flag == 2){
inputNum();
}
if(flag>2){
System.out.println("命令输入错误!请根据提示重新输入命令!");
inputCommand();
}
}catch(Exception e){
System.out.println("命令输入错误!请根据提示重新输入命令!");
inputCommand();
}
}
public static void inputName(){
String[] Books = {"Math","英语","化学"};
System.out.println("输入图书名称:");
Scanner sc = new Scanner(System.in,"GBK");
try{
String name = sc.next();
System.out.println("book:"+name);
inputCommand();
for(int i=0;i<Books.length;i++){
if (Books[i].equals(name)){
System.out.println("book:"+name);
}
}
}catch(Exception e){
System.out.println("图书不存在!");
inputCommand();
}
}
public static void inputNum(){
String[] Books = {"高数","英语","化学"};
System.out.println("输入图书序号:");
Scanner sc = new Scanner(System.in);
try{
int num = sc.nextInt();
System.out.println("book:"+Books[num]);
inputCommand();
}catch(Exception e){
System.out.println("图书不存在!");
inputCommand();
}
}
}