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

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

作業(yè)提交 。

InputException.java

package com.imooc.test;

public class InputException extends Exception {

???? public InputException() {

???????? super();

???????? System.out.println("命令輸入錯(cuò)誤!請(qǐng)根據(jù)提示輸入數(shù)字命令!");

???? }

???? public InputException(String message) {

???????? super(message);

???????? System.out.println(message);

???? }

}

BookBorrow.java

package com.imooc.test;


import java.util.Arrays;

import java.util.InputMismatchException;

import java.util.Scanner;


public class BookBorrow {

???? private static String[] books = { "高數(shù)", "積分變換", "線性代數(shù)", "馬克思哲學(xué)" };

????

???? public static void main(String[] args) {

???????? // TODO Auto-generated method stub

???????? BookBorrow bkb = new BookBorrow();

???????? bkb.borrow();

???? }

????

???? public void borrowByName(Scanner input) throws InputException {

???????? System.out.println("輸入圖書名稱:");

???????? String name = input.next();

???????? if (-1 == Arrays.binarySearch(books, name)) {

???????? ???? System.out.println("圖書不存在!");

? ? ? ? ? ? ?throw new InputException();

???????? } else {

???????????? System.out.println("book: " + name);

???????? }

???? }

????

???? public void borrowByNumber(Scanner input) throws InputException {

???????? System.out.println("輸入圖書序號(hào):");

???????? int num = input.nextInt();

???????? if (num < 1 || num > books.length) {

???????? ???? System.out.println("圖書不存在!");

? ? ? ? ? ? ? throw new InputException();

???????? } else {

???????? ???? System.out.println("book: " + books[num - 1]);

???????? }

???? }

????

???? public void borrow() {

???????? Scanner input = new Scanner(System.in);

???????? System.out.println("輸入命令:1-按照名稱查找圖書;2-按照序號(hào)查找圖書");

???????? try {

???????????? switch (input.nextInt()) {

???????????????? case 1:

???????????????? ???? borrowByName(input);

???????????????? ???? break;

???????????????? case 2:

???????????????????? borrowByNumber(input);

???????????????????? break;

???????????????? default:

???????????????? ???? System.out.println("命令輸入錯(cuò)誤!請(qǐng)根據(jù)提示輸入數(shù)字命令!");

???????????????????? borrow();

???????????????????? break;

???????????? }

???????? } catch(InputException e) {

????????

???????? }catch (InputMismatchException e) {

???????????? System.out.println("命令輸入錯(cuò)誤!請(qǐng)根據(jù)提示輸入數(shù)字命令!");

???????? } catch (Exception e) {

???????????? // TODO: handle exception

???????????? e.printStackTrace();

???????? } finally {

???????????? borrow();

???????????? input.close();

???????? }

???? }

}


正在回答

2 回答

程序存在一些問題:1. 根據(jù)要求查詢的第二步 ? 根據(jù)書名或序號(hào)查詢?nèi)糨斎霐?shù)據(jù)格式不正確沒有一個(gè)明確的提示錯(cuò)誤的類型以及錯(cuò)誤后應(yīng)繼續(xù)執(zhí)行主程序的操作。2. 要求根據(jù)書名或圖書序號(hào)查詢查詢,圖書和序號(hào)應(yīng)存在唯一對(duì)應(yīng)關(guān)系,所以最好把數(shù)據(jù)存儲(chǔ)在map集合中。

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

路過請(qǐng)多指教

恍恍惚惚朦朦朧

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

舉報(bào)

0/150
提交
取消

作業(yè)提交 。

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

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

幫助反饋 APP下載

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

公眾號(hào)

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