作業(yè)寫(xiě)完了
package Demo;
import java.util.Scanner;
public class BorrowBook {
public static void main(String[] args) {
BorrowBook test=new BorrowBook();
test.bobo();
}
public void bobo(){
String Books[]= {"數(shù)據(jù)結(jié)構(gòu)","高數(shù)","java語(yǔ)言","英語(yǔ)"};
System.out.println("*******歡迎來(lái)到慕課網(wǎng)借書(shū)系統(tǒng)*******");
System.out.println("輸入命令:1-按照名稱(chēng)查找圖書(shū);2-按照序號(hào)查找圖書(shū)");
Scanner input=new Scanner(System.in);
try{
int num=input.nextInt();
if(num==1){
System.out.println("輸入圖書(shū)名稱(chēng):");
Scanner input1=new Scanner(System.in);
String Bookname =input1.nextLine();
int a=-1;
for(int i=0;i<Books.length;i++) {
if(Books[i].equals(Bookname)) {
System.out.println("book:"+Books[i]);
System.out.println("*************您借書(shū)成功*************");
a=1;
}
}
if(a==-1) {
throw new NobookException("圖書(shū)不存在!");
}
}else if(num==2){
System.out.println("輸入圖書(shū)名序號(hào):");
Scanner input2=new Scanner(System.in);
? ? int Booknum =input2.nextInt();
if(Booknum>0&&Booknum<=Books.length) {
System.out.println("book:"+Books[Booknum-1]);
System.out.println("*************您借書(shū)成功*************");
}else {
throw new NobookException("圖書(shū)不存在!");
}
}
}catch(NobookException e) {
System.out.println(e.getMessage());
bobo();
// }catch(ErrorCodeException e){
// ? ? System.out.println("命令輸入錯(cuò)誤!請(qǐng)根據(jù)提示輸入數(shù)字命令");
// bobo();
}catch(Exception e){
? ? System.out.println("命令輸入錯(cuò)誤!請(qǐng)根據(jù)提示輸入數(shù)字命令");
bobo();
}
}
}
2019-04-16
NobookException沒(méi)有定義啊