定义一个ArrayList集合,存储一批书籍,书籍具有书名、作者、价格三个属性, 键盘录入一个书名时,显示该书籍的详细信息。

时间:2025-03-10 17:00:41
import .*; class Book{ String name; String author; double price; public Book(String name){ this.name = name; } public Book(String name,String author,double price){ this.name = name ; this.author = author; this.price = price; } public boolean equals(Book b){ return this.(); } public String toString(){ return "书名: "+this.name+" 作者: "+this.author+" 零售价: "+this.price; } } class Demo6{ public static void main(String[] args){ String str = null; ArrayList<Book> list = new ArrayList<Book>(); (new Book("三国演义","罗贯中",53.5)); (new Book("水浒传","施耐庵",54.5)); (new Book("西游记","吴承恩",60)); (new Book("红楼梦","曹雪芹、高鹗",85)); Scanner sc = new Scanner(System.in); while(()){ str=(); break; } Iterator it = (); while(()){ Book b =(Book)(); if((new Book(str))){ System.out.println("成功查询到"+str+"的详细信息"); System.out.println(b); break; }else{ if(!()){ System.out.println("没有找到你查询的书籍"); } } } } }