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 For Each Loop

David Hinton
David Hinton
3,070 Points

So back to that ScrabblePlayer. I found that it's not enough to know if they just have a tile of a specific characte

I seem to be having a real hard time absorbing the information in these videos , I watch them ( multiple times) I write the code down but when it comes to the questions I completely fall apart its like things just don't make sense should I just give up trying? even when I go to try find the answers on the forums sometimes they don't make sense.

Anyway this task just really stumped me I feel like the videos don't go fully into depth and everything is just rushed

ScrabblePlayer.java
public class ScrabblePlayer {
  private String mHand;

  public ScrabblePlayer() {
    mHand = "";
  }

  public String getHand() {
   return mHand;
  }

  public int getTileCount(char t){
    int count = 0; 
    for (char tile : mHand.toCharArray()){
      if (tile == t) {
         count++;
      }
    }

    return count;
  }
}

  public void addTile(char tile) {
    // Adds the tile to the hand of the player
    mHand += tile;
  }

  public boolean hasTile(char tile) {
   return mHand.indexOf(tile) > -1;
  }
}

2 Answers

Jennifer Nordell
seal-mask
STAFF
.a{fill-rule:evenodd;}techdegree
Jennifer Nordell
Treehouse Teacher

Well... I don't know about anything else, but definitely don't give up! Listen, persistence generally pays off... eventually. Now, a while ago I posted a rather detailed explanation about this challenge. Take a look at my explanation and see if it doesn't clarify it a bit! I sincerely hope this helps, and by all means... hang in there!

https://teamtreehouse.com/community/help-to-solve-code-challenge-also-please-explain-the-logic-and-thanks-in-advance

David Hinton
David Hinton
3,070 Points

Thank you so much Jennifer! I just had a look over what you posted and it was awesome! I love how it explains each line really helps me to understand whats going on and why :)

Tristan Smith
Tristan Smith
3,171 Points

Two questions here,

First "[..]should I just give up trying?"

Not at all! :D The fact that you're "struggling" through it and pushing on is great. [1]

Second, it looks like you have an extra "}" on line 22. I checked your code and ran it through without that bracket, and it passed! :)

[1] Edit: To add, some people learn well when struggling through a problem. I'm one of those people. I could spend days on something struggling through it, going through every possible solution I can think of, then, it hits me, and I got it! And b/c of that whole ordeal I can recall it well.

David Hinton
David Hinton
3,070 Points

Thank you man I really appreciate it!

Tristan Smith
Tristan Smith
3,171 Points

No problem! Make sure to check out the link Jennifer posted above/below too.