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

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

圖書館借書系統(tǒng)-Java異常的學(xué)習(xí)和處理

標(biāo)簽:
Java
  • 定义了三个类
  • ErrorCodeException.java

public class ErrorCodeException extends Exception {

    public ErrorCodeException(){
    }

    public ErrorCodeException(String message){
        super(message);
    }
}
  • NoExitBookException.java

public class NoExitBookException extends Exception {

    public NoExitBookException() {
    }

    public NoExitBookException(String message) {
        super(message);
    }
}
  • BorrowBookSystem.java

public class BorrowBookSystem {

    String[] library = {"Java", "Python", "javascript", "Android", "iOS", "Linux", "Unix", "C", "C++", "C#", "Ruby", "Django", "Flask"};

    public static void main(String[] args) {
        BorrowBookSystem system = new BorrowBookSystem();
        system.borrow();
    }

    public void borrow() {
        while (true) {
            int command = 0;
            try {
                command = command();
            } catch (ErrorCodeException e) {
                System.out.println(e.getMessage());
            }
            if (command == 1) {
                try {
                    queryBookName();
                } catch (NoExitBookException e) {
                    System.out.println(e.getMessage());
                }
            } else if (command == 2) {
                try {
                    queryBookCode();
                } catch (ErrorCodeException e) {
                    System.out.println(e.getMessage());
                } catch (NoExitBookException e) {
                    System.out.println(e.getMessage());
                }
            }

        }
    }

    public int command() throws ErrorCodeException {
        int result;
        System.out.println("输入查询命令:1-按照图书名称查询,2-按照图书序列号查询。");
        Scanner scanner = new Scanner(System.in);
        String command = scanner.next().trim();
        if (command.equals("1")) {
            result = 1;
        } else if (command.equals("2")) {
            result = 2;
        } else {
            throw new ErrorCodeException("命令输入错误!请根据提示输入数字命令!");
        }
        return result;
    }

    private void queryBookCode() throws ErrorCodeException, NoExitBookException {
        System.out.println("输入图书序列号:");
        Scanner scanner = new Scanner(System.in);
        String next = scanner.next().trim();
        int number;
        try {
            number = Integer.parseInt(next);
        } catch (Exception e) {
            throw new ErrorCodeException("命令输入错误!请根据提示输入数字命令!");
        }
        try {
            String bookName = library[number];
            System.out.println("book:" + bookName);
        } catch (Exception e) {
            throw new ErrorCodeException("图书不存在!");
        }
    }

    private void queryBookName() throws NoExitBookException {
        System.out.println("输入图书名称:");
        Scanner scanner = new Scanner(System.in);
        String next = scanner.next().trim();
        boolean result = false;
        for (int i = 0; i < library.length; i++) {
            if (library[i].equals(next)) {
                System.out.println("book:" + library[i]);
                result = true;
                break;
            }
        }
        if (!result) {
            throw new NoExitBookException("图书不存在!");
        }
    }
}
點(diǎn)擊查看更多內(nèi)容
22人點(diǎn)贊

若覺得本文不錯(cuò),就分享一下吧!

評(píng)論

作者其他優(yōu)質(zhì)文章

正在加載中
移動(dòng)開發(fā)工程師
手記
粉絲
5
獲贊與收藏
110

關(guān)注作者,訂閱最新文章

閱讀免費(fèi)教程

感謝您的支持,我會(huì)繼續(xù)努力的~
掃碼打賞,你說多少就多少
贊賞金額會(huì)直接到老師賬戶
支付方式
打開微信掃一掃,即可進(jìn)行掃碼打賞哦
今天注冊(cè)有機(jī)會(huì)得

100積分直接送

付費(fèi)專欄免費(fèi)學(xué)

大額優(yōu)惠券免費(fèi)領(lǐng)

立即參與 放棄機(jī)會(huì)
微信客服

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

幫助反饋 APP下載

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

公眾號(hào)

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

舉報(bào)

0/150
提交
取消