酷代码 AI
菜单
全部AI  /  热门  /  AI写代码神器
服务商

修改图书信息: 设计一个方法 updatebook(string isbn, string newtitle, string newauthor, int newpublicationyear),根据提供的 isbn 更新相应图书的标题、作者和出版年份。

可以这样来实现这个方法: ```java public void updateBook(String isbn, String newTitle, String newAuthor, int newPublicationYear) { for(Book book : allBooks) { if(book.getIsbn().equals(isbn)) { book.setTitle(newTitle); book.setAuthor(newAuthor); book.setPublicationYear(newPublicationYear); System.out.println("图书信息更新成功!"); return; } } System.out.println("未找到对应的图书信息"); } ``` 其中,allBooks 是一个存储所有图书信息的数据结构,可以是一个 List<Book> 类型的变量。通过遍历所有的图书信息,找到与提供的 isbn 相匹配的图书,然后更新其、作者和出版年份。如果找不到对应 isbn 的图书信息,则输出提示信息。 [2024-07-04 23:10:31 | AI写代码神器 | 474点数解答]

相关提问