Java Java Data Structures Organizing Data Interfaces

Adi Strasser
Adi Strasser
2,692 Points

Java - Data Structures : Interfaces

Error:

Example.java:30: error: cannot find symbol                               
        Arrays.sort(treets);                                             
        ^                                                                
  symbol:   variable Arrays                                              
  location: class Example                                                
./com/teamtreehouse/Treet.java:34: error: cannot find symbol             
            return mDescription(other.mDescription);                     
                   ^                                                     
  symbol:   method mDescription(String)                                  
  location: class Treet                                                  
2 errors

Code: (Example.java)

import java.util.Date;

import com.teamtreehouse.Treet;

public class Example {

    public static void main(String[] args) {
        Treet treet = new Treet(
            "craigdennis",
            "Want to be famous? Simply tweet about Java and use " +
            "the hashtag #treet. I\'ll use your tweet in the new " +
            "@treehouse course about data structures.",
            new Date(1421849732000L)
        );

        Treet secondTreet = new Treet(
            "journeytocode",
            "@treehouse makes learning Java sooooooo fun! #treet",
            new Date(1421878767000L)
        );

        System.out.printf("This 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);
        }
    }
}

Code: (Treet.java)

package com.teamtreehouse;

import java.util.Date;
import java.util.Arrays;

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("Treet: \"%s\" by %s on %s", 
                             mDescription, mAuthor, mCreationDate);
    }

    @Override
    public int compareTo(Object obj) {
        Treet other = (Treet) obj;

        if (equals(other)) {
            return 0;
        }

        int dateCmp = 
mCreationDate.compareTo(other.mCreationDate);

        if (dateCmp == 0) {
        return mDescription(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#@']+");
    }
}

3 Answers

Hello Strasser,

I believe it will compile clean with import java.util.Arrays; added to your Example.class.

Tonnie Fanadez
Tonnie Fanadez
UX Design Techdegree Graduate 21,841 Points

First of all import import java.util.Arrays on Example. java Secondly you have left out something on compareTo () method inside the Treet.java class. The return statement should look like this: return mDescription.compareTo(other.mDescription);

Adi Strasser
Adi Strasser
2,692 Points

*** Code not complete for this lesson, but it should compile.