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

My code..

Ran into a bit of a roadblock on this challenge can anyone help out?

Tweet.java
public static final int MAX_MISSES = 7;
public class Tweet {
  private String mText;

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

  public String getText() {
    return mText;
  }
  public int getTileCount(char letter);
    int tileCount = 0;
    for(char tile : mHand.toCharArray());
      if(mHand.indexOf(tile) >=0);
        tileCount++;
      }
     return tileCount;
}}

1 Answer

Michael Hess
Michael Hess
24,512 Points

Hi Tim McKyer,

For task one, we need to declare a constant that is 140 characters. The naming convention for constants, in Java, is to capitalize all of the letters. A constant is declared by using the keyword final.

For task 2 , we need to make a method that will return the remaining characters of the MAX_CHAR constant we declared in task 1. We do this by subtracting the characters that have already been used from the MAX_CHAR constant. getText().length() will give us the characters that have already been used. So, MAX_CHAR - getText().length(); will give us the remaining characters out of 140.

public class Tweet {
  private String mText;
  public static final int MAX_CHAR = 140; //task 1

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

  public String getText() {
    return mText;
  }
  //task 2
  public int getRemainingCharacters(){

    return  MAX_CHAR - getText().length();    
  }
}

If you have any other questions feel free to ask! Hope this helps!

Thank Michael, It makes sense to me now xD

Michael Hess
Michael Hess
24,512 Points

My pleasure -- glad I could help you!