Java

Harshavardhan Gangavarapu
Harshavardhan Gangavarapu
9,106 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,515 Points

The variable answer is nowhere defined.

Harshavardhan Gangavarapu
Harshavardhan Gangavarapu
9,106 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
PRO
Daniel Turato
Java Web Development Techdegree Graduate 30,086 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();
  }
}