title: how to implement a book ranking - JAVA
body: <p>Could someone please help me in implementing a method in JAVA that gets the 50 most sold books of a bookstore?</p>
  <p>This is the <code>Bookstore</code> class:</p>
  <pre class="lang-java prettyprint-override"><code>public class Bookstore implements Serializable {
  
      private static final long serialVersionUID = -3099048826035606338L;
      private boolean populated;
      private final List&lt;Country&gt; countryById;
      private final Map&lt;String, Country&gt; countryByName;
      private final List&lt;Address&gt; addressById;
      private final Map&lt;Address, Address&gt; addressByAll;
      private final List&lt;Customer&gt; customersById;
      private final Map&lt;String, Customer&gt; customersByUsername;
      private final List&lt;Author&gt; authorsById;
      private final List&lt;Book&gt; booksById;
      private final List&lt;Cart&gt; cartsById;
      private final List&lt;Order&gt; ordersById;
      private final LinkedList&lt;Order&gt; ordersByCreation;
  </code></pre>
  <p><code>OrderLine</code> is another class with the details of the order, like:</p>
  <pre class="lang-java prettyprint-override"><code>    private final Book book;
      private final int qty;
      private final double discount;
      private final String comments;
  </code></pre>
  <p>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:</p>
  <pre class="lang-java prettyprint-override"><code>public List&lt;Book&gt; getBestSellers(String subject) {
  
           ArrayList&lt;Book&gt; bestSellers = new ArrayList&lt;Book&gt;();
           for (Order order : ordersById) {
               if (order.getStatus().equalsIgnoreCase(&quot;SHIPPED&quot;)) {
                   for (int i=0; i&lt;order.getLines().size(); i++){
  </code></pre>