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 Strings and Chars

Amit Dhamankar
Amit Dhamankar
4,163 Points

Cannot solve the problem.

I have tried to create an object in this task. I am calling a constructor of this class ScrabblePlayer. I passed the value "Amit" to this instructor and then tried to add the incoming character which is accepted by the variable tile in the "addTile" method. But I am not getting the answer. Please help. Thanks in advance

ScrabblePlayer.java
public class ScrabblePlayer {
    private String mHand;

    public ScrabblePlayer() {
        mHand = "";
    }

    public String getHand() {
       return mHand;
    }

    public addTile(char tile) {
        // Adds the tile to the hand of the player
      ScrabblePlayer sb = new ScrabblePlayer("Amit");
      mHand = mhand + 'tile';
    }

    public boolean hasTile(char tile) {
       return false;
    }
}

2 Answers

Kane Stoboi
Kane Stoboi
21,919 Points

I'm pretty sure that you don't need to create a new "ScrabblePlayer object so you can remove

ScrabblePlayer sb = new ScrabblePlayer("Amit");

Also you should look at what you are assigning to mHand in the addTile method. That seems to be where the problem is.

mahmoud abdelbary
mahmoud abdelbary
3,841 Points

you simply forgot to add a return type to your method ,,scene it return nothing the return type will be void

public void addTile(char tile) { //your code }

and i think you shouldn't create an object in that method you can assign a value to your variable throw the constructor

public ScrabblePlayer(String Hand) { mHand = Hand; }