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 Objects (Retired) Creating the MVP Remaining Characters

Java Objects.

Add a new method to return the remaining characters based on length of mText.

Tweet.java
public class Tweet {
    public static final int MAX_LENGTH = 140;
  private String mText;

  public Tweet(String text) {
    while (text.length() < MAX_LENGTH) {
    mText = text;}
  }

  public String getText() {
    return mText;
  }

  public int getRemainingChars() {
    return MAX_LENGTH - mText.length();
  }


}

What is wrong in the code???

2 Answers

Kourosh Raeen
Kourosh Raeen
23,733 Points

Hi Kangan - There is nothing wrong with your code. I just tried it and it passed. Give it another try.

I m still getting BUMMER!! Try Again. I dont know what the problem is, and I cant go any further in the Java Objects till i clear this. Please suggest.

Kourosh Raeen
Kourosh Raeen
23,733 Points

OK, the problem is in the constructor. I'm not sure why you have while loop there but change that back to the original code:

public class Tweet {
  public static final int MAX_LENGTH = 140;
  private String mText;

  public Tweet(String text) {
    mText = text;
  }

  public String getText() {
    return mText;
  }

  public int getRemainingChars() {
    return MAX_LENGTH - mText.length();
  }

}

Thanks a lot Kourosh, it worked.