圖書(shū)管理系統(tǒng)

public class LibraryManage {
    Scanner scanner = new Scanner(System.in);
    BookSet bookSet = new BookSet();
    SimpleDateFormat outBook = new SimpleDateFormat("yyyy-MM-dd");

    public void initial() {
        Book java = new Book();
        java.bookSet("java基礎(chǔ)教程",false,"2015-7-1",1);

        Book mysql = new Book();
        mysql.bookSet("數(shù)據(jù)庫(kù)技術(shù)",true,"",0);

        Book renYue = new Book();
        renYue.bookSet("人月神話",true,"",0);

        bookSet.book[0] = java;
        bookSet.book[1] = mysql;
        bookSet.book[2] = renYue;
    }

    public void startMenu() {
        boolean flag1 = true;
        int choose;
        int fanhui;
        do {
            System.out.println("歡迎使用圖書(shū)管理系統(tǒng)");
            System.out.println("——————————————————————————————————————————");
            System.out.println("1. 新增圖書(shū)");
            System.out.println("2. 查看圖書(shū)");
            System.out.println("3. 刪除圖書(shū)");
            System.out.println("4. 借出圖書(shū)");
            System.out.println("5. 歸還圖書(shū)");
            System.out.println("6. 退   出");
            System.out.println("請(qǐng)選擇:");
            choose = scanner.nextInt();
            switch (choose) {
                case 1:
                    System.out.println("---> 新增圖書(shū)");
                    add();
                    break;
                case 2:
                    System.out.println("---> 查看圖書(shū)");
                    chakan();
                    break;
                case 3:
                    System.out.println("---> 刪除圖書(shū)");
                    delete();
                    break;
                case 4:
                    System.out.println("---> 借出圖書(shū)");
                    out();
                    break;
                case 5:
                    System.out.println("---> 歸還圖書(shū)");
                    guihuan();
                    break;
                case 6:
                    System.out.println("---> 退   出");
                    break;
            }
            System.out.print("輸入0返回:");
            fanhui = scanner.nextInt();


        }while( fanhui == 0 ) ;
    }

    private void add() {
        System.out.print("請(qǐng)輸入圖書(shū)名稱:");
        String name = scanner.next();
        boolean flagDelete = true;
        int count = 0;
        String date = "";
        
        Book newBook = new Book();
        newBook.bookSet(name,flagDelete,date,count);
        for (int i = 0; i < bookSet.book.length; i++) {
            if ( bookSet.book[i] == null ) {
                bookSet.book[i] = newBook;
                break;
            }
        }
        System.out.println("增加" + newBook.name + "成功");
    }

    private void chakan() {
        System.out.println("序號(hào) \t狀 態(tài) \t  名稱  \t\t借出日期");
        for (int i = 0; i < bookSet.book.length; i++) {
            if ( bookSet.book[i] != null) {
                bookSet.book[i].print(i+1 );
            }
        }
        System.out.println("***********************************");
    }

    private void delete() {
        System.out.println("請(qǐng)輸入你要?jiǎng)h除圖書(shū)的名稱:");
        String deleteBookName = scanner.next();
        for (int i = 0; i < bookSet.book.length; i++) {
            if ( bookSet.book[i] != null ) {
                if ( deleteBookName.equals(bookSet.book[i].name) ) {
                    if (bookSet.book[i].flag ) {
                        int j = i;
                        while ( bookSet.book[j+1] != null ) {
                            bookSet.book[j] = bookSet.book[j+1];
                            j++;
                        }
                        bookSet.book[j] = null;
                        System.out.println("刪除成功");
                    }else {
                        System.out.println("已借出的書(shū)不能刪除");
                        break;
                    }
                }else {
                    System.out.println("圖書(shū)館不存在此書(shū)");
                    break;
                }

            }

        }


        }



    private void out() {
        System.out.print("請(qǐng)輸入圖書(shū)名稱:");
        String bookName = scanner.next();
        String outDate;
        for (int i = 0; i < bookSet.book.length; i++) {
            if ( bookSet.book[i] !=null && bookName.equals(bookSet.book[i].name) ) {
                if ( bookSet.book[i].flag ) {
                    System.out.print("請(qǐng)輸入借出日期(年-月-日):");
                    outDate = scanner.next();
                    bookSet.book[i].count = bookSet.book[i].count + 1;
                    bookSet.book[i].bookSet(bookName,false,outDate,bookSet.book[i].count);
                    System.out.println("借出成功");
                    break;
                }else {
                    System.out.println("此書(shū)已被借走");
                }

            }
        }
    }

    private void guihuan() {
        System.out.print("請(qǐng)輸入圖書(shū)名稱:");
        String guihuanBook = scanner.next();
        String guihuanBookDate;
        for (int i = 0; i < bookSet.book.length; i++) {

            if ( guihuanBook.equals(bookSet.book[i].name) ) {
                if ( bookSet.book[i].flag ) {
                    System.out.println(bookSet.book[i].name + "未借出");
                }else {
                    System.out.println("請(qǐng)輸入歸還日期:");
                    guihuanBookDate = scanner.next();
                    System.out.println("歸還《" + bookSet.book[i].name + "》成功!");
                    System.out.println("借出日期為:" + bookSet.book[i].date);
                    System.out.println("歸還日期為:" + guihuanBookDate);
                    System.out.println("應(yīng)付租金(元)");
                }
                break;
            }else {
                System.out.println("圖書(shū)館不存在此書(shū)");
            }
        }

    }

}
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書(shū)系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

  • 今天感恩節(jié)哎,感謝一直在我身邊的親朋好友。感恩相遇!感恩不離不棄。 中午開(kāi)了第一次的黨會(huì),身份的轉(zhuǎn)變要...
    余生動(dòng)聽(tīng)閱讀 10,853評(píng)論 0 11
  • 彩排完,天已黑
    劉凱書(shū)法閱讀 4,476評(píng)論 1 3
  • 表情是什么,我認(rèn)為表情就是表現(xiàn)出來(lái)的情緒。表情可以傳達(dá)很多信息。高興了當(dāng)然就笑了,難過(guò)就哭了。兩者是相互影響密不可...
    Persistenc_6aea閱讀 129,659評(píng)論 2 7

友情鏈接更多精彩內(nèi)容