title: Printing out the correct combination after comparing the parameters of several elements
body: <p>We were given the below exercise, where the desired result is to print out the most valueable combination of "treasures" (can also be just one if it holds the most value and the right size) for the given sack size:</p>
  
  <pre><code>public class Treasure {
      private String name;
      private Integer size;
      private Double value;
  
      public Treasure(String name, Integer size, Double value) {
          this.name = name;
          this.size = size;
          this.value = value;
      }
  
      public String getName() {
          return name;
      }
  
      public void setName(String name) {
          this.name = name;
      }
  
      public Integer getSize() {
          return size;
      }
  
      public void setSize(Integer size) {
          this.size = size;
      }
  
      public Double getValue() {
          return value;
      }
  
      public void setValue(Double value) {
          this.value = value;
      }
  
      //can also create new methods inside this class
  
      @Override
      public String toString() {
          return "Treasure [name=" + name + ", size=" + size + ", value=" + value + "]";
      }
  
  }
  </code></pre>
  
  <pre><code>import java.util.ArrayList;
  import java.util.List;
  
  public class Thief {
  
      public static void main(String[] args) {
          Thief thief = new Thief();
          List&lt;Treasure&gt; treasuresList = thief.fillTreasures();
          List&lt;Treasure&gt; sack = thief.steal(30, treasuresList);
          thief.printTreasures(sack);
      }
  
      private List&lt;Treasure&gt; fillTreasures() {
          List&lt;Treasure&gt; treasuresList = new ArrayList&lt;Treasure&gt;();
  
          treasuresList.add(new Treasure("Ring", 1, 450d));
          treasuresList.add(new Treasure("Necklace", 1, 400d));
          treasuresList.add(new Treasure("Jewel", 4, 100d));
          treasuresList.add(new Treasure("Coin", 4, 200d));
          treasuresList.add(new Treasure("Bracelet", 5, 550d));
          treasuresList.add(new Treasure("Pistol", 5, 1000d));
          treasuresList.add(new Treasure("Clock", 10, 450d));
          treasuresList.add(new Treasure("Glass", 15, 1000d));
          treasuresList.add(new Treasure("Telescope", 30, 3100d));
          treasuresList.add(new Treasure("Gold", 35, 3500d));
          treasuresList.add(new Treasure("Silver", 33, 3300d));
          treasuresList.add(new Treasure("Bronze", 31, 3100d));
  
          return treasuresList;
      }
  
      public List&lt;Treasure&gt; steal(int sackSize, List&lt;Treasure&gt; treasuresList) {
          //my effort so far
          for (int i = 0; i &lt; treasuresList.size(); i++) {
              Treasure treasure = treasuresList.get(i);
  
              //removes those whose size is greater than the sack
              if (treasure.getSize() &gt; sackSize) {
                  treasuresList.remove(i--);
              }
  
              //don't really know how to proceed from this point on
  
          }
  
          return treasuresList;
      }
  
      private void printTreasures(List&lt;Treasure&gt; treasuresList) {
          for (int i = 0; i &lt; treasuresList.size(); i++) {
             Treasure treasure = treasuresList.get(i);
             System.out.println(treasure);
          }
      }
  }
  </code></pre>
  
  <p>So in this particular case, where the sack size is 30, the output should be:</p>
  
  <pre><code>Treasure [name=Ring, size=1, value=450.0]
  Treasure [name=Coin, size=4, value=200.0]
  Treasure [name=Bracelet, size=5, value=550.0]
  Treasure [name=Pistol, size=5, value=1000.0]
  Treasure [name=Glass, size=15, value=1000.0]
  </code></pre>
  
  <p>Because the combination of these treasures gives the most value for the given sack size.</p>
  
  <p>Any idea how to tackle this problem and write the logic would be greatly appreciated.</p>