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

Twitter application

How to create access level modifiers, and make them unchangeable and accessible. Need help!

Tweet.java
public class Tweet {
  private String mText;

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

  public String getText() {
    return mText;
  }

}

2 Answers

Christopher Augg
Christopher Augg
21,223 Points

April,

The instructions say, "Please add a new constant to store the maximum number of characters allowed which is 140. Use the proper access level modifiers to make it unchangeable and accessible right off of the class. Follow the proper naming convention."

The first thing to notice is that we need to add a constant to our code. We use constants to represent things that we know will never change (i.e hours in a day etc.). Our constant will be the max number of characters allowed in a tweet.

Whenever we need to add a constant to our code, we use the keyword final to make it unchangeable. Furthermore, we use all caps letters and place underscores in between words. Therefore, we know we need something like:

       accessor final int MAX_CHARS = 140;

The instructions also state that we need to use an accessor that allows access right off the class. This means that we need to make it public and use the static keyword as well.

       public static final int MAX_CHARS = 140;

I hope this helps.

Regards,

Chris

Neil Gordon
Neil Gordon
8,823 Points

here is some code i used as well

public static final int MAX_TWEET = 140;