当库中仅存储 1 个手册时提示用户输入

Prompt user input when only 1 manual stored in library

我正在开发一个图书馆应用程序,它允许存储、借阅、归还和删除技术手册。

目前我正在处理我的应用程序的借阅部分,我已经启用它通过输入指定的手册索引号来询问用户他们希望借用哪本手册(从存储在图书馆中的手册列表中)。此处显示:

但是,如果图书馆中仅存储了 1 本手册,则应用程序会自动借用它,而无需向用户询问索引号。此处显示:

虽然自动借用唯一可用的书是有意义的,但我仍然希望用户被要求提供索引号,因为这样可以最大程度地减少混淆。

这是我正在使用的相关代码:

public static void borrowManual(){
    displayManualList();

    //register user's Manual choice.
    ManualChoice = (Console.readInteger(Messages.enterManualIndexMessage, Messages.ManualIndexNotInListMessage, 0, Library.ManualList.size() - 1));

    borrowLoop:
    while(Menu.menuChoice == 3){
        //Check if the Manual to be borrowed is available.
        //ManualChoice = (Console.readInteger(Messages.enterManualIndexMessage, Messages.ManualIndexNotInListMessage, 1, Library.ManualList.size()));

        if ((ManualList.get(ManualChoice).status.equalsIgnoreCase(status1)) && (ManualList.size() >= ManualChoice)){
            //Print the borrowed Manual information and change the Manual status to borrowed.
            ManualList.get(ManualChoice).status = "Borrowed";
            ManualList.get(ManualChoice).borrower = User.userName;
            ManualList.get(ManualChoice).borrowDate = "Today.";
            ManualList.get(ManualChoice).returnDate = "In two weeks.";
            //Add the borrowed Manual to the borrowedManuals arraylist:
            borrowedManuals.add(ManualList.get(ManualChoice));

            System.out.printf("\n==========================================================================\n");
            System.out.printf("\n\nYou have chosen the following Manual:\n\n %s\n\n", ManualList.get(ManualChoice).displayManual());
            System.out.println("Please return the Manual within two weeks!\n");
            System.out.println("\n--------------------------------------------------------------------------");
            System.out.println("\n                             Manual borrowed!\n");
            System.out.println("--------------------------------------------------------------------------\n");
            break borrowLoop;

        }else if(ManualList.get(ManualChoice).status.equalsIgnoreCase(status2) && ManualList.size() >= ManualChoice){
            System.out.println("\n\n--------------------------------------------------------------------------");
            System.out.println("\n            "
                    + " The Manual you wish to borrow is already on loan.");
            System.out.println("\n--------------------------------------------------------------------------\n");
            break borrowLoop;

        }else if(ManualChoice > ManualList.size()-1){
            System.out.println(Messages.noSuchManualMessage);
            break borrowLoop;
        }
    }
    Menu.displayMenu();
}

如果有人知道如何让我的应用程序始终要求用户输入索引号,请告诉我:D

这是你的问题,如果只有一本手册,它会自动借用它。我认为您可以删除此 && 检查,它应该可以正常工作。

(ManualList.size() >= ManualChoice)){