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

Harshavardhan Gangavarapu
Harshavardhan Gangavarapu
13,727 Points

Create a public method named getRemainingCharacterCount that returns an int representing how many characters they have

public class Tweet {
  String mText;
  private String text;
  public static final int MAX_CHARS=140;
  public Tweet(String text) {
   mText = text;
  }

  public String getText() {
    return text;
  }
  int answer=MAX_CHARS-mText.length();
  public void setText(String text) {
    mText = text;
  }
  public int getRemainingCharecterCount(){
    return answer;
  }
}

2 Answers

Martin Klestil
Martin Klestil
5,520 Points

The variable answer is nowhere defined.

Harshavardhan Gangavarapu
Harshavardhan Gangavarapu
13,727 Points

Did not complete the challenge. Below is the error which occurred with your code:

Tweet.java:10: error: cannot find symbol return text; ^ symbol: variable text location: class Tweet Note: JavaTester.java uses unchecked or unsafe operations. Note: Recompile with -Xlint:unchecked for details. 1 error

Daniel Turato
seal-mask
PLUS
.a{fill-rule:evenodd;}techdegree seal-36
Daniel Turato
Java Web Development Techdegree Graduate 30,124 Points

Well first there is a few issues with your code, for starters you don't need to create an outside field for answer as that's what the method is used for. Also, even if you were thinking of adding a field for this value you would put it above the methods and not in between them. I can't see the challenge you on to see if the code will be correct for this but I think this should work:

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

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

  public String getText() {
    return text;
  }
  public void setText(String text) {
    mText = text;
  }
  public int getRemainingCharecterCount(){
    return MAX_CHARS - mText.length();
  }
}