java代码如何按作者筛选书籍?
这是我的任务:给了你一个暑假要读的书的清单,但你只想读某个作者的书
写一个方法
公共列表筛选器书籍(列表读取列表、字符串作者) 它将书籍列表作为参数,从readingList中删除所有不是由给定作者编写的书籍,然后返回结果列表
您可以通过调用Book来访问书籍的作者。getAuthor()。这本书是供参考的
给出了两个类强>
书。爪哇
public class Book
{
private String title;
private String author;
public Book(String theTitle, String theAuthor)
{
title = theTitle;
author = theAuthor;
}
public String getTitle()
{
return title;
}
public String getAuthor()
{
return author;
}
public String toString()
{
return title + " by " + author;
}
public boolean equals(Book other)
{
return title.equals(other.title) && author.equals(other.author);
}
}
单元测试
public List<Book> filterBooks(List<Book> readingList, String author)
{
// Remove all Books from the readingList that are not
// written by the given author. Return the resulting List
}
我真的不知道如何解决这个问题。。。我知道这可能需要解释很多,但我真的需要围绕这种逻辑编码来思考。。。非常感谢您的帮助
共 (0) 个答案