title: Using the Comparable interface to sort through dates
body: <p>I'm trying to write a simple program that will sort the order of given dates, by sorting from earliest date to latest.</p>
  <p>I'm able to sort the dates by their years, however when 2 dates have the same year and I need to sort by month, it starts having problems. I've been trying to nest if-statements and tried implementing while loops but I can't quite seem to get it right. I know that in my if statements, I'm missing some kind of statement that tells java to sort by <code>month &lt; other.month</code> and <code>day &lt; other.day</code> but I can't quite get it right...</p>
  <p>Input/Output currently:</p>
  <blockquote>
  <p>[10/5 1999, 19/5 1999, 10/3 1999, 19/3 1999, 10/5 2000, 19/5 2000, 10/3 2000, 19/3 2000]</p>
  <p>[10/3 1999, 10/3 2000, 19/3 1999, 10/5 1999, 10/5 2000, 19/5 1999, 19/3 2000, 19/5 2000]</p>
  </blockquote>
  <pre><code>class Date implements Comparable&lt;Date&gt; {
      private int year;
      private int month;
      private int day;
  
      public Date(int year, int month, int day) {
          this.year = year;
          this.month = month;
          this.day = day;
      }
  
      @Override
      public int compareTo(Date other) {
          if(year &lt; other.year) {
              return Integer.compare(this.year, other.year);
          }
          if(year == other.year) {
              return Integer.compare(this.month, other.month);
          }
          if(month == other.month) {
              return Integer.compare(this.day, other.day);
          }
          return day;
      }
  
      public String toString() {
          return day + &quot;/&quot; + month + &quot; &quot; + year;
      }
  }
  </code></pre>