title: Sorting Array in natural order
body: <p>OK, using your implement Comparator.  It returns errors complaing about the string value being incompatible with the return int.</p>
  
  <pre><code>class cdinventoryItem implements Comparable&lt;cdinventoryItem&gt; {
  
          private String Ptitle;
          private int PitemNumber;
          private int PnumberofUnits;
          private double PunitPrice;
          private double Evalue;
  
  
          public cdinventoryItem(String title, int itemNumber, int numberofUnits, double unitPrice ){
  
                  Ptitle = title;
                  PitemNumber = itemNumber;
                  PnumberofUnits = numberofUnits;
                  PunitPrice = unitPrice;
  
          }
   public int compareTo(cdinventoryItem otherItem) {
      return this.Ptitle.compareTo(otherItem.getTitle());
    }
  
    public int getTitle() {
      return Ptitle;
    }
  
  
  
          public double stockValue () {
              return PnumberofUnits * PunitPrice;
          }
  
  
          public double getEntireStockValue () {
              Evalue = Evalue + this.stockValue();
              return Evalue;
          }
  
  
          @Override public String toString(){
  
  
              NumberFormat dformat = new DecimalFormat("#0.00");
  
  
              StringBuilder ouput  = new StringBuilder();
              String New_Line = System.getProperty("line.separator");
  
                  ouput.append ("The product number of my CD is: " + PitemNumber + New_Line);
                  ouput.append ("The title of the CD is: " + Ptitle + New_Line);
                  ouput.append ("I have " + PnumberofUnits + " units in stock." + New_Line);
                  ouput.append ("The total value of my inventory on this product is: " + dformat.format (stockValue()) + New_Line);
                  return ouput.toString();
              }
  
  }
  
  
  
  public class cdinventoryprogram {
  
      public static void main(String[] args) {
  
      NumberFormat dformat = new DecimalFormat("#0.00");
      double Tvalue= 0.0;
  
      int DEFAULT_LENGTH = 3;
  
          System.out.println ("Welcome to my CD inventory program!!");
          System.out.println ("");
  
  
              cdinventoryItem  initem[] = new cdinventoryItem [DEFAULT_LENGTH];
  
              initem [0] = new cdinventoryItem ("The Illusionist", 1, 5, 15.99);
              initem [1] = new cdinventoryItem ("Matrix", 2, 3, 14.99);
              initem [2] = new cdinventoryItem ("Old School", 3, 6, 12.99);
  
  
              Arrays.sort(initem,
              new Comparator&lt;cdinventoryItem&gt;() {
              public int compare(cdinventoryItem item1, cdinventoryItem item2) {
              return item1.getTitle().compareTo(item2.getTitle());
      }});
  
                  for ( cdinventoryItem currentcdinventoryItem : initem ){
                  System.out.println( currentcdinventoryItem );
                  Tvalue = Tvalue + currentcdinventoryItem.getEntireStockValue();
                  }
  
                  System.out.println ("The total value of my entire inventory is:");
                  System.out.println ( "$" + dformat.format (Tvalue));
                  System.out.println();
      }}
  </code></pre>