我在这里创建了一个类:
class book{
String book_nm;
String author_nm;
String publication;
int price;
book(String book_nm,String author_nm,String publication,int price){
this.book_nm=book_nm;
this.author_nm=author_nm;
this.publication=publication;
this.price=price;
}
}
现在我想根据作者和书名搜索特定值
ArrayList<book> bk = new ArrayList<book>();
我使用 switch case 创建了一个菜单驱动程序
case 3: System.out.println("Search:"+"\n"+"1.By Book Name\n2.By Author Name");
Scanner s= new Scanner(System.in);
int choice=s.nextInt();
while(choice<3){
switch(choice){
case 1:System.out.println("Enter the name of the book\n");
String name=s.next();
-------
case 2:System.out.println("Enter the name of the author\n");
String name=s.next(); ------
}
}
我知道如何在 ArrayList 中查找和搜索特定元素,但不知道如何查找对象。
MYYA
www说
相关分类