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

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

Books System design

標(biāo)簽:
Java

//Define a Books Class;

package com.imooc;
public class Books {
public String name;
public int num;

public Books(int num, String name){
    this.num = num;
    this.name = name;
}

}

//Define a LibrarySystem;

package com.imooc;

import java.util.Scanner;

public class LibrarySystem {
//Step1. Declare an array of book (named books);
Books[] books = new Books[10];

public static void main(String[] args) throws Exception {
    LibrarySystem system = new LibrarySystem();
    system.start();
}

public void start() throws Exception {

    *//Step2. Initialise the array of books;*
    fillbooksArray(books);

    *//Step3. Asking user to choose a way to search the book*
    UserInput01();
}

private void fillbooksArray(Books[] books) {
    books[0] = new Books(1,"Glen story");
    books[1] = new Books(2,"Jane");
    books[2] = new Books(3,"Human-being history");
    books[3] = new Books(4,"Sorting");
    books[4] = new Books(5,"Cooking");
    books[5] = new Books(6,"How to write Java");
    books[6] = new Books(7,"Economy");
    books[7] = new Books(8,"Education method");
    books[8] = new Books(9,"Human-being mind");
    books[9] = new Books(10,"History");

}

private void UserInput01() throws Exception {
    try {
        System.out.println("1.Searching according the name;   2.Searching according the index");
        Scanner scan = new Scanner(System.in);
        int Input = scan.nextInt();
        if(Input==1){
            InputName();
        }else if(Input==2){
            InputIndex();
        }else{
            System.out.println("Please choose number1 or number2");
            UserInput01();
        }
    } catch (Exception e) {
        System.out.println("Your input is wrong, please follow the instruction to choose again");
        UserInput01();
    }
}

private void InputName() throws Exception {
    try {
        System.out.println("Please enter the Name of the Book~");
        Scanner scan = new Scanner(System.in);
        String Input01 = scan.next();
        boolean isMatch = false;
        for (int i = 0; i < books.length; i++) {
            if(Input01.equals(books[i].name)){
                System.out.println("the book name is: " + books[i].name + "    the Index of book is: " + books[i].num);
                isMatch = true;
            }
        }
        if(isMatch == false){
            System.out.println("We cannot find this book, please enter the name of the book again~");
            InputName();
        }
    } catch (Exception e) {
        System.out.println("Sorry, the type of name is wrong, please do it again");
        InputName();
    }
}

private void InputIndex() throws Exception {
    try {
        System.out.println("Please enter the Index of the Book~");
        Scanner scan = new Scanner(System.in);
        int Input02 = scan.nextInt();
        boolean isMatch = false;
        for (int i = 0; i < books.length; i++) {
            if(Input02 == books[i].num){
                System.out.println("the book name is: " + books[i].name + "    the Index of book is: " + books[i].num);
                isMatch = true;
            }
        }
        if(isMatch == false){
            System.out.println("We cannot find this book, please enter a interger between 1-10");
            InputIndex();
        }
    } catch (Exception e) {
        System.out.println("sorry, your input is wrong, do it again");
        InputIndex();
    }
}

}

//Run it:

1.Searching according the name; 2.Searching according the index
2
Please enter the Index of the Book~
a
sorry, your input is wrong, do it again
Please enter the Index of the Book~
13
We cannot find this book, please enter a interger between 1-10
Please enter the Index of the Book~
11
We cannot find this book, please enter a interger between 1-10
Please enter the Index of the Book~
8
the book name is: Education method the Index of book is: 8

Process finished with exit code 0

點(diǎn)擊查看更多內(nèi)容
TA 點(diǎn)贊

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

評(píng)論

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

正在加載中
  • 推薦
  • 評(píng)論
  • 收藏
  • 共同學(xué)習(xí),寫下你的評(píng)論
感謝您的支持,我會(huì)繼續(xù)努力的~
掃碼打賞,你說(shuō)多少就多少
贊賞金額會(huì)直接到老師賬戶
支付方式
打開(kāi)微信掃一掃,即可進(jìn)行掃碼打賞哦
今天注冊(cè)有機(jī)會(huì)得

100積分直接送

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

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

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

購(gòu)課補(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
提交
取消