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

why isnt this working... it makes sense right? yes, no, maybe... what am i doing wrong?

public class Tweet { final static public int MAX_CHARS=140;

private String text;

public int getRemainingCharacterCount(){ int remainingchars=MAX_CHARS-text.length();

while(remainingchars<= MAX_CHARS){
  //System.out.printf("You have %d character left",remainingchars);

}
return remainingchars;

}

public Tweet(String text) { this.text = text; }

public String getText() { return text; }

public void setText(String text) { this.text = text; } }

2 Answers

Hey there

Your getRemainingCharacterCount method should like something like this: public int getRemainingCharacterCount(){ return MAX_CHARS - text.length(); }

This will give you a pass on the challenge.

Just FYI: The while statement that you have, it has to go in the .class that contains a main method (which runs a program) and it this case it would look something like this:

(let's assume you've created a new "Tweet" object in a class that contains the main method Tweet tweet = new Tweet("tweet text goes here"); )

then, somewhere underneath it you should call a while loop like:

while(tweet.getRemainingCharacterCount<= MAX_CHARS){ System.out.println("You have %d character left", tweet.getRemainingCharacterCount); }

I hope this makes some sense... Good luck with studies!

Thanks Ruslan