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

What am I doing wrong?

whats wrong with this code?

ScrabblePlayer.java
public class ScrabblePlayer {
  private String mHand;

  public ScrabblePlayer() {
    mHand = "";
  }

  public String getHand() {
   return mHand;
  }

  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;
  }
  public TYPE getTileCount(ARGUMENT); {
    for (char ITERATOR: mHand.toCharArray()) { 
      if(EXPRESSION) { 
    }
  }
}

1 Answer

public TYPE getTileCount(ARGUMENT); {
    for (char ITERATOR: mHand.toCharArray()) { 
      if(EXPRESSION) {

    }
  }

The problem is this method. You need to change TYPE, ARGUMENT, EXPRESSION. You dont have to change the word ITERATOR, but you probably should.

  1. The 'TYPE' is the return type for this method, probably an int
  2. The 'ARGUMENT' is the variable that accept input into the method.
  3. The 'EXPRESSION' should check if the 'ITERATOR' is equal to the char passed in as an argument
  4. You are missing one closing bracket.
  5. Right after the argument parenthesis you have a semi-colon, that shouldn't be there.

I think this should get you started, Let me know if you need anything else.