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 Splitting Strings

Sean Flanagan
Sean Flanagan
33,235 Points

Problems yet again

Hi.

I have a feeling I'm going to need help at every turn while I'm learning Java.

For some reason, when using the console, when I move the cursor, anything I type just overtypes text to the right of it. Is there any way I can change that please?

Also, I'm unable to copy and paste despite using Ctrl C and Ctrl V.

As for my code, I'm getting more error messages.

Example.java:

import java.util.Date;

import com.teamtreehouse.Treet;

public class Example {
  public static void main(String []args) {
    Treet treet = new Treet(
      "craigsdennis",
      "Feeling overwhelmed by learning to #code?" + 
      "Try out this thought hack I whipped up:  http://buff.ly/1LjAZrJ  #development #webdev",
      new Date(1437084178)
    );
    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.java:

package com.teamtreehouse;

import java.util.Date;

public class Treet {
  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 "Treet: \"" + mDescription + "\" - @" + mAuthor;
  }

  public String getAuthor() {
    return mAuthor;
  }

  public String getDescription() {
    return mDescription;
  }

  public Date getCreationDate() {
    return mCreationDate;
  }

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

Snapshot: https://w.trhou.se/4eypbl06gy

I've forked my workspace.

Thanks in advance for any help.

Sean :-)

Sean Flanagan
Sean Flanagan
33,235 Points

Hi Dmitriy. I've just added a pair of parentheses in that line and now it's working. It's saying "word" down the left of the console. Thanks. :-)

Jon Kussmann
Jon Kussmann
Courses Plus Student 7,254 Points

Hi Sean,

It does look like Dmitriy helped you with your "word" problem. You should not be using quotes around the word.. "world". When you use quotes, it uses the String "word" and not the variable word.

I'll change his comment to an answer in case you feel it is sufficient to give a "best answer" to him.

2 Answers

Dmitriy Nefedchenko
Dmitriy Nefedchenko
1,925 Points

Hi, Sean. Not sure I can tell you something reasonable about command line operations, but here are couple of things I noticed about code.

— you need to add trailing parenthesis right after method declaration in Treet class, so, getWords -> getWords() — change "word" to word inside for loop to print not just a literal, but actual value :-)

Dmitriy Nefedchenko
Dmitriy Nefedchenko
1,925 Points

Glad to hear that, Sean!

Yes, Jon is right, you need to remove quotes from "word"

for (String word: treet.getWords()) { // System.out.println("word"); "word" ---> word System.out.println(word); }