I am trying to calculate the average price of the books in a library in a year:
public class Library

```
private List<Book> books;

private final String name;

public Library(String name) {
    this.name = name;
    books = new ArrayList<>();
}

public Library(List<Book> books, String name) {
    this.books = books;
    this.name = name;
}

public List<Book> getBooks() {
    return books;
}

public void setBooks(List<Book> books) {
    this.books = books;
}

public String getName() {
    return name;
}

public boolean addBook(Book b) {
    return books.add(b);
}

// find average price of books in library in given year

public double calcAveragePriceInYear(int year) {
    double total = 0.0;
    for ( Book i : books) {
        if (i.getYear() == year) {
            total = total + i.getPrice();
        }

    }
    return total/ Collections.frequency(books, year);

}

```

Here is the method I am trying to create:
// find average price of books in library in given year

```
public double calcAveragePriceInYear(int year) {
        double total = 0.0;
        for ( Book i : books) {
            if (i.getYear() == year) {
                total = total + i.getPrice();
            }

        }
        return total/ Collections.frequency(books, year);

    }

```

Here is the Book Class:

```
public class Book {

    private String name;
    private String author;
    private String isbn;
    private int year;
    private double price;

    public Book(String name, String author, String isbn, int year, double price) {
        this.name = name;
        this.author = author;
        this.isbn = isbn;
        this.year = year;
        this.price = price;
    }

```

Question is, how can I divide the total with number of times the given year is in the Library?

return total / Collections.frequency(books, year); keeps returning 0