Could someone please help me in implementing a method in JAVA that gets the 50 most sold books of a bookstore?
This is the Bookstore
class:
public class Bookstore implements Serializable {
private static final long serialVersionUID = -3099048826035606338L;
private boolean populated;
private final List<Country> countryById;
private final Map<String, Country> countryByName;
private final List<Address> addressById;
private final Map<Address, Address> addressByAll;
private final List<Customer> customersById;
private final Map<String, Customer> customersByUsername;
private final List<Author> authorsById;
private final List<Book> booksById;
private final List<Cart> cartsById;
private final List<Order> ordersById;
private final LinkedList<Order> ordersByCreation;
OrderLine
is another class with the details of the order, like:
private final Book book;
private final int qty;
private final double discount;
private final String comments;
I started doing this: (I have to consider the Order status SHIPPED and the subject of the book), but I don't know if this is right or what to do next, for instance, how to sum the quantities by bookId and order the bestSellers list:
public List<Book> getBestSellers(String subject) {
ArrayList<Book> bestSellers = new ArrayList<Book>();
for (Order order : ordersById) {
if (order.getStatus().equalsIgnoreCase("SHIPPED")) {
for (int i=0; i<order.getLines().size(); i++){