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("图书不存在!");
}
}
點擊查看更多內(nèi)容
6人點贊
評論
評論
共同學(xué)習(xí),寫下你的評論
評論加載中...
作者其他優(yōu)質(zhì)文章
正在加載中
感謝您的支持,我會繼續(xù)努力的~
掃碼打賞,你說多少就多少
贊賞金額會直接到老師賬戶
支付方式
打開微信掃一掃,即可進行掃碼打賞哦