第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定

終于寫出來(lái)了,還需要改進(jìn)的地方。。。。

package?com.kandy.class8;

public?class?Book?{
????private?String?name;
????private?int?id;

????public?String?getName()?{
????????return?name;
????}

????public?Book(int?id,String?name)?{
????????this.name?=?name;
????????this.id?=?id;
????}

????public?void?setName(String?name)?{
????????this.name?=?name;
????}

????public?int?getId()?{
????????return?id;
????}

????public?void?setId(int?id)?{
????????this.id?=?id;
????}
}
package?com.kandy.class8;

public?class?BookNotFindExeption?extends?Exception{
????public?BookNotFindExeption(){}
????public?BookNotFindExeption(String?message)?{
????????super(message);
????}
}
package?com.kandy.class8;
import?java.util.Scanner;

public?class?InitialBook?{
????//創(chuàng)建圖書
????Book[]?books?=?{
????????????new?Book(1,?"語(yǔ)文"),
????????????new?Book(2,?"數(shù)學(xué)"),
????????????new?Book(3,?"英語(yǔ)"),
????};
????//輸入
????Scanner?input;

????//顯示圖書菜單,進(jìn)入查找分類
????public?void?showMenu()?{
????????try?{
????????????System.out.println("借書請(qǐng)按編號(hào)或書名(1:按編號(hào)/2:按書名)");
????????????System.out.println("編號(hào)\t\t?書名");
????????????for?(Book?book?:?books)?{
????????????????System.out.println("?"?+?book.getId()?+?"\t\t《"?+?book.getName()?+?"》");
????????????}
????????????System.out.print("請(qǐng)輸入1或2,0退出:");
????????????input?=?new?Scanner(System.in);

????????????int?num?=?input.nextInt();
????????????switch?(num)?{
????????????????case?0:
????????????????????System.exit(0);
????????????????????break;
????????????????case?1:
????????????????????findForId();
????????????????????break;
????????????????case?2:
????????????????????findForName();
????????????????????break;
????????????????default:
????????????????????showMenu();
????????????}
????????}?catch?(Exception?e)?{
????????????System.out.println("輸入有誤,請(qǐng)根據(jù)提示輸入。");
????????????showMenu();
????????}?finally?{
????????????input.close();
????????}
????}

????//按編號(hào)查找
????public?void?findForId()?{
????????try?{
????????????System.out.print("請(qǐng)輸入圖書的編號(hào),輸入0返回上一級(jí):");
????????????input?=?new?Scanner(System.in);
????????????int?num?=?input.nextInt();
????????????if?(num?==?0)?showMenu();

????????????boolean?isFind?=?false;
????????????for?(Book?book?:?books)?{
????????????????if?(book.getId()?==?num)?{
????????????????????isFind?=?true;
????????????????????System.out.println("********找到圖書:(編號(hào):"?+?book.getId()?+?"書名:"?+?book.getName()?+?")");
????????????????????showMenu();
????????????????????break;
????????????????}
????????????}
????????????if?(!isFind)?{
????????????????throw?new?BookNotFindExeption("未找到此編號(hào)的圖書!");
????????????}
????????}?catch?(BookNotFindExeption?e)?{
????????????System.out.println(e.getMessage());
????????????findForId();
????????}?catch?(Exception?e)?{
????????????System.out.println("輸入有誤,請(qǐng)根據(jù)提示輸入。");
????????????findForId();
????????}?finally?{
????????????input.close();
????????}
????}

????//按書名查找
????public?void?findForName()?{
????????try?{
????????????System.out.print("請(qǐng)輸入圖書的名稱,輸入0返回上一級(jí):");
????????????input?=?new?Scanner(System.in);
????????????String?name?=?input.nextLine();
????????????if?(name.equals("0"))?showMenu();

????????????boolean?isFind?=?false;
????????????for?(Book?book?:?books)?{
????????????????if?(book.getName().equals(name))?{
????????????????????isFind?=?true;
????????????????????System.out.println("*********找到圖書:(編號(hào):"?+?book.getId()?+?"書名:"?+?book.getName()?+?")");
????????????????????showMenu();
????????????????????break;
????????????????}
????????????}
????????????if?(!isFind)?{
????????????????throw?new?BookNotFindExeption("未找到此名稱的圖書!");
????????????}
????????}?catch?(BookNotFindExeption?e)?{
????????????System.out.println(e.getMessage());
????????????findForName();
????????}?catch?(Exception?e)?{
????????????System.out.println("輸入有誤,請(qǐng)根據(jù)提示輸入。");
????????????findForName();
????????}?finally?{
????????????input.close();
????????}
????}

????//程序入口
????public?static?void?main(String[]?args)?{
????????InitialBook?in?=?new?InitialBook();
????????//顯示圖書列表
????????in.showMenu();
????}
}


正在回答

1 回答

?真的牛,不過(guò)用遞歸,可能會(huì)造成內(nèi)存溢出,就是一直按住回車的情況下

0 回復(fù) 有任何疑惑可以回復(fù)我~

舉報(bào)

0/150
提交
取消

終于寫出來(lái)了,還需要改進(jìn)的地方。。。。

我要回答 關(guān)注問(wèn)題
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)