如何在Java的图书馆项目中检出书籍和搜索书籍?

如何在Java的图书馆项目中检出书籍和搜索书籍?,java,Java,我正在为我的Java编程类做一个库系统项目。我需要能够按作者或标题搜索图书数组中的图书列表。此外,我还想看看如何在系统中检出图书。如果有任何帮助或见解,我将不胜感激。searchBooks和checkoutBook方法位于底部。再次感谢 真诚地, 月亮 成套工程; 导入java.util.ArrayList; 导入java.util.Scanner; 公共班级图书馆{ 静态扫描仪输入=新扫描仪(System.in); ArrayList booklist=新建ArrayList(); Array

我正在为我的Java编程类做一个库系统项目。我需要能够按作者或标题搜索图书数组中的图书列表。此外,我还想看看如何在系统中检出图书。如果有任何帮助或见解,我将不胜感激。searchBooks和checkoutBook方法位于底部。再次感谢

真诚地, 月亮

成套工程;
导入java.util.ArrayList;
导入java.util.Scanner;
公共班级图书馆{
静态扫描仪输入=新扫描仪(System.in);
ArrayList booklist=新建ArrayList();
ArrayList用户=新建ArrayList();
静态int运行=0;
字符串搜索;
公共静态void main(字符串[]args){
(新建库()).run();
}
公开募捐{
while(true){
System.out.println(“**********************欢迎来到公共图书馆!”;
System.out.println(“请从以下选项中选择:”);
System.out.println(“*************************************************************************************************************************”);
System.out.println(“1:创建新帐户”);
System.out.println(“2:管理员登录”);
System.out.println(“3:用户登录”);
System.out.println(“0:Exit”);
int option=input.nextInt();
开关(选件){
案例1:newAccount();中断;
案例2:管理();中断;
案例3:userLogin();中断;
案例0:系统退出(可选);中断;
案例5:返回;
默认值:System.out.println(“选项错误,请重试”);
}
}
}
公共无效地址簿(){
Book book1=新书(“权力游戏”、“幻想”、“乔治·马丁”、“一本关于龙的书”,9001,5);
Book book2=新书(《哈利波特》、《冒险》、《JK罗琳》、《一个男孩上魔法学校》,23454,3);
Book book3=新书(“嘉莉”、“恐怖”、“斯蒂芬·金”、“一个女孩疯了”,3332,15);
Book book4=新书(《龙珠球》、《动作漫画》、《东山昭》、《有力量的男孩与邪恶战斗》,27894,2);
图书目录。添加(第1册);
增加(第2册);
增加(第3册);
增加(第4册);
}
私有void userLogin(){
扫描仪键盘=新扫描仪(System.in);
System.out.println(“输入您的用户名”);
字符串user=keyboard.nextLine();
System.out.println(“输入密码”);
String pass=keyboard.nextLine();//在扫描中查看所选文件
if(用户相等(“olumide1”)&通过相等(“umbc”)){
System.out.println(“**********************欢迎回家,用户!”);
System.out.println(“请从以下选项中选择:”);
System.out.println(“*************************************************************************************************************************”);
System.out.println(“1:签出一本书:”);
System.out.println(“2:搜索一本书:”);
System.out.println(“3:退出库:”);
int option=input.nextInt();
开关(选件){
案例1:结帐簿();中断;
案例2:搜索簿();中断;
案例3:系统退出(0);
}
}否则{
系统输出打印(“重试”);
}
}
公共书籍{
System.out.println(“您今天在搜索哪本书?”);
booksearch=input.nextLine();
}
私人作废签出簿(){
}

要搜索一本书,只需遍历您的
图书列表
并按标题或作者进行搜索。此外,我建议您的
searchBooks()
方法应返回一个
Book
实例:

public Book searchBooks() {
    System.out.println("Which book are you searching for today?");
    booksearch = input.nextLine();
    for (Book book : booklist)
    {
        if (book.getTitle().contains(booksearch) || book.getAuthor().contains(booksearch)
        {
             return book; 
        }
    }
    return null; //no book was found
}

要跟踪已签出/免费图书,只需创建已签出图书的新
列表
。您的
checkOutBook
方法应该接受
Book
参数:

private void checkOutBook(Book book) {
    checkedOutBooks.add(book);
} 

对于SearchBook方法,您可以使用hashmap、google并花一些时间在上面。请提供签出簿的详细信息,以及需要在其中执行的操作。

创建2个Pojo

     Class Book
    {
    int id;
    int quantity;
     String bookName;
    Author author;
    } 

    Class Author
    {
    int authorId;
    String authorName;
    List<Integer>bookIdsList;
    }
教材
{
int-id;
整数;
字符串书名;
作者;
} 
类作者
{
int authorId;
字符串authorName;
ListbookIdsList;
}
使用3个贴图初始化类

        TreeMap<String,Integer>bookSearchMap  //String is the bookName // Integer is the book Id  
        TreeMap<String,Author>authorSearchMap //String is the authorName
        HashMap<Integer,Book>bookData  // for checking out the book with the Id of book
TreeMapbookSearchMap//String是书名//Integer是图书Id
TreeMapauthorSearchMap//String是authorName
HashMapbookData//用于签出Id为book的书籍
因此,2树映射将帮助您进行搜索 HashMap将帮助您签出。
如果需要前缀搜索,可以使用TRIE结构,但必须实现该结构。

Javascript!=JAVA请不要发送垃圾标签。对于
searchBooks
,您将从用户那里获得信息,然后在“图书列表”上迭代,找到匹配的图书。我猜
类中有一个
.getTitle()
可能会用到。目前,您提供的信息太少(缺少
Book
class),工作太少(甚至没有尝试实现这些方法)。
        TreeMap<String,Integer>bookSearchMap  //String is the bookName // Integer is the book Id  
        TreeMap<String,Author>authorSearchMap //String is the authorName
        HashMap<Integer,Book>bookData  // for checking out the book with the Id of book