亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定

emmmm

package?borrow_books;
import?java.util.Scanner;

public?class?InitialBorrow{
????static?int?num;
????static?String?input;
public?static?void?main(String[]?args)?throws?ErrorCommandException{????????
????System.out.println("歡迎進入借書系統!\n書目\n1-紅樓夢\n2-西游記\n3-三國演義\n4-水滸傳\n請輸入序號或書名選擇借閱!");
????Scanner?sc=new?Scanner(System.in);
????input=sc.nextLine();//input獲取輸入的內容
????try?{
????????InitialBorrow?IB?=new?InitialBorrow();
????????IB.inStr();
????}?catch?(Exception?e)?{
????????e.printStackTrace();
????????throw?new?ErrorCommandException();
????}finally?{
????????sc.close();
????????System.out.println("程序運行完畢!");
????????System.exit(0);
????}
}
public?void?inNum?()?throws?NumFailedException{
????try?{
????????num?=?Integer.parseInt(input);
????????if?(num>=1?&?num<=4)?{
????????????System.out.println(num+"-"+Book.getBookName(num)+"借閱成功!^-^");
????????}
????????else?{
????????????throw?new?BookNotExistException();
????????}
????}catch(Exception?e)?{
????????throw?new?NumFailedException();
????}????
}
public?void?inStr()?throws?BookNotExistException{
????try?{
????????inNum();????
????}?catch?(NumFailedException?e)?{//使用序號判定失敗后,使用NumFailedException作為信號
????????if?(input.equals("紅樓夢")||input.equals("西游記")||input.equals("三國演義")||input.equals("水滸傳"))?{
????????????System.out.println(Book.getBookNum(input)+"-"+input+"借閱成功!^-^");
????????}else?{
????????????throw?new?BookNotExistException();
????????}
????}
}
}

public?class?Book?{

????public?static?int?getBookNum(String?newinput)?{
????????
????????switch?(newinput)?{
????????case?"紅樓夢":
????????????return?1;
????????case?"西游記":
????????????return?2;
????????case?"三國演義":
????????????return?3;
????????case?"水滸傳":
????????????return?4;
????????default:
????????????return?0;
????????}
????????????
????}
????public?static?String?getBookName(int?newinput)?{
????????
????????switch?(newinput)?{
????????case?1:return"紅樓夢";
????????case?2:return"西游記";
????????case?3:return"三國演義";
????????case?4:return"水滸傳";
????????default:return"";
????????}
????}
????????
????}
??
public?class?ErrorCommandException?extends?Exception{

????public?ErrorCommandException()?{
????????super("命令錯誤!");
????}

}

public?class?BookNotExistException?extends?Exception{

????public?BookNotExistException()?{
????????super("圖書不存在!");
????}

}

public?class?NumFailedException?extends?Exception?{}


正在回答

2 回答

???

0 回復 有任何疑惑可以回復我~

????

0 回復 有任何疑惑可以回復我~

舉報

0/150
提交
取消
Java入門第三季
  • 參與學習       409766    人
  • 解答問題       4543    個

Java中你必須懂得常用技能,不容錯過的精彩,快來加入吧

進入課程
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號