Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Java Java Data Structures Organizing Data Interfaces

Problem in Workspace

Here is my Snapshot - https://w.trhou.se/6p6iqi1a51 It says error - '}' expected in line 35 when my program is completely fine.

./com/teamtreehouse/Treet.java:35: error: missing return statement                                                                  
  }                                                                                                                                 
  ^                                                                                                                                 
1 error
Treet.java
package com.teamtreehouse;

import java.util.Date;

public class Treet implements Comparable {
  private String mAuthor;
  private String mDescription;
  private Date mCreationDate;

  public Treet(String author, String description, Date creationDate)
  {
    mAuthor = author;
    mDescription = description;
    mCreationDate = creationDate; 
  }

  @Override
  public String toString() {
    return String.format(": \"%s\" by %s on %s",mDescription,mAuthor,mCreationDate);
  }

  @Override
  public int compareTo(Object obj) {     
    if (obj instanceof Treet) {
      Treet other =  (Treet) obj;  
        if(equals(other)) { 
      return 0;
    }
     int dateCmp = mCreationDate.compareTo(other.mCreationDate);  
    if (dateCmp == 0) { 
      return mDescription.compareTo(other.mDescription);
    }
    return dateCmp;
    }
  }

  public String getAuthor() {
     return mAuthor;
  }

  public String getDescription() {
    return mDescription;
  }

  public Date getCreationDate() {
    return mCreationDate;
  }

  public String[] getWords() {
    return mDescription.toLowerCase().split("[^\\w@#']+");
  }

}
Example.java
import java.util.Date;

import java.util.Arrays;

import com.teamtreehouse.Treet;


public class Example{

 public static void main(String[] args){

   Treet treet = new Treet("Soumyadeep","bleh bleh BLLLEEHHHHHH", new Date(1434813953000L));
   Treet secondTreet = new Treet("journeytocode",
      "@treehouse makes learning Java sooooo fun! #treet",
      new Date(1421878767000L));
   System.out.printf("There is a new Treet: %s. %n",treet);
   System.out.println("The words are: ");
   for (String word: treet.getWords()) {
     System.out.println(word);
     Treet[] treets = {treet, secondTreet};
     Arrays.sort(treets);
     for (Treet exampleTreet: treets) {
       System.out.println(exampleTreet);
     }
   }
 }

}

1 Answer

Jonathan Grieve
MOD
Jonathan Grieve
Treehouse Moderator 91,252 Points

Hi there.

In your workspace you need one more return statement in your compareTo method of your Treet class. You need to return a "falsey" value.

Try

return 0;

Before the final closing brace of your compareTo() method.

Thank you, sir. My problem was solved.