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

jhonatan gonzales
jhonatan gonzales
2,950 Points

how?

HOW?

Tweet.java
public class Tweet {

  public static final int MAX_CHAR=140;

  private String mText;

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

  public String getText() {
    return mText;
  }
 public int getRemainingChars () {
 return MAX_CHAR - mText.lenght();
 }
}

1 Answer

Luciano Bruzzoni
Luciano Bruzzoni
15,518 Points

Hey, I'm not 100% sure what you mean by how; but hope this helps. When you tweet something Tweeter allows for a max of 140 characters to be typed. So that's what MAX_CHAR represents. Then, you want to show the user the number of characters they have left to type which is done with the getRemainingChars function. This function will get mText, which is the text(tweet) the user is typing, and with the .length method it will tell how many characters the text currently has. Substract 140(MAX_CHAR) from the mText char length and you will have the remaining characters to type!

Not sure if that answers the question, if not you could be a bit more specific and maybe I can help further. Good luck!