title: Using Comparable interface for primitive data types
body: <p>Apologies if this is a silly question, i am relatively new to programming.</p>
  
  <p>Basically i had a homework question to create a post office scenario that supports two types of items: items sent by the air, and items that are sent by the sea. for each type, i used a calcFee method to calculate the total shipping costs.</p>
  
  <p>The second part of the homework asks to extend the Item class so that it implements the Comparable interface, where items are sorted on their calcFee value. Now i understand that primitive data types cannot be sorted from the Comparable interface. Because the question specifically asks to use the Comparable interface am i doing something wrong or am i just creating the program incorrectly</p>
  
  <p>Any help would be greatly appreciated.</p>
  
  <pre><code>package homework3;
      import java.util.ArrayList;
      import java.util.Collections;
  /**
   *
   * @author Josh
   */
  public class Homework3 {
  
      /**
       * @param args the command line arguments
       */
      public static void main(String[] args) {
              ArrayList&lt;Item&gt; items = new ArrayList();
              items.add(new airItems(11, "josh", "sam", 295));
              items.add(new airItems(11, "zosh", "sam", 295));
              items.add(new seaItems(11, "aosh", "sam", 11, 12, 15));
  
              Collections.sort(items);
  
              for (Item i : items){
                  i.calcFee();
                  i.print();
  
              }
      }
  
  }
  
  class Item implements Comparable&lt;Item&gt;{
  
      int id;
      String from;
      String to;
      double fee;
  
      public Item(int id, String from, String to){
          this.id = id;
          this.from = from;
          this.to  = to;
  
  
      }
  
      public void print(){
          System.out.println("id: " + id + "\tFrom: " + from + "\tTo: " + to + "\tFee: " + fee);
      }
  
      public double calcFee(){
          return 0;
      }
  
  
      @Override
      public int compareTo (Item item1){
          return this.fee.compareTo(item1.calcFee());
      }
  }
  
  class airItems extends Item{
      long weight;
  
      public airItems(int id, String from, String to, int weight){
          super(id, from, to);
          this.weight = weight;
      }
  
      public void print(){
          super.print();
          System.out.println("Weight: " + weight);
          System.out.println("");
  
      }
  
      @Override
      public double calcFee(){
          if (weight &lt; 100){
              fee = 2.5;
          }
          else if (weight &lt; 200) {
              fee = 5;
          }
          else if (weight &lt; 300) {
              fee = 7.5;
          }
      return fee;    
      }
  
  }
  
  
  class seaItems  extends Item{
      int length;
      int width;
      int depth;
  
      public seaItems(int id, String from, String to, int length, int width, int depth){
          super(id, from, to);
          this.length = length;
          this.width = width;
          this.depth = depth;
      }
  
      @Override
      public double calcFee(){
          if  (length &lt;= 10 &amp;&amp; width &lt;= 10 &amp;&amp; depth &lt;= 10){
              fee = 5;
          }
          else if  (length &lt;= 20 &amp;&amp; width &lt;= 20 &amp;&amp; depth &lt;= 20){
              fee = 10;
          }
          if  (length &lt;= 50 &amp;&amp; width &lt;= 50 &amp;&amp; depth &lt;= 50){
              fee = 5;
          }
          else if (length &gt; 50 &amp;&amp; width &gt; 50 &amp;&amp; depth &gt; 50 ){
              fee = 0;
          }
          return fee;
      }
  
      @Override
      public void print(){
          super.print();
          System.out.println("Length: " + length + "\tWidth:" + width + "\tdepth" + depth);
          System.out.println("");
      }
  
  
  
  }
  </code></pre>