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 trialChristopher Mlalazi
Front End Web Development Techdegree Graduate 17,305 PointsCreate a public method named getRemainingCharacterCount that returns an int representing how many characters they have l
I simple have no idea how to get past this code challenge can somebody please help I am still new to java and some of these explanations I find them confusing:
public class Tweet {
private String mText;
public static final int MAX_CHARS= 140;
public Tweet(String text) {
while(text.length() < MAX_CHARS){
mText = text;
}
}
public String getText() {
return mText;
}
public getRemainingCharacterCount(){
return int mText < 140;
}
}
public class Tweet {
private String mText;
public static final int MAX_CHARS= 140;
public Tweet(String text) {
while(text.length() < MAX_CHARS){
mText = text;
}
}
public String getText() {
return mText;
}
public getRemainingCharacterCount(){
return int mText < 140;
}
}
6 Answers
Lawrence Babay
6,941 Pointspublic int getRemainingCharacterCount() { return MAX_CHARS - text.length(); }
You don't need to create mtext. you shouldn't replace text to mtext, because of this you created an error. Hope this helps.
Thanks, Lawrence
Robert Stamate
13,227 PointsFor me ``` public class Tweet { private String text; public static final int MAX_CHARS= 140;
public Tweet(String text) { this.text = text; }
public String getText() { return text; }
public void setText(String text) { this.text = text; }
public int getRemainingCharacterCount(){ return MAX_CHARS - text.length(); } } ```
It worked out perfectly. I haven't changed this.text and it was easier.
Gavin Mace
30,747 PointsThanks Robert!
The mText stuff was driving me crazy with lots of compile errors. Replacing the 2nd part with {this.text = text;} saved me.
Kourosh Raeen
23,733 PointsYou can subtract the length of mText
from the maximum number of characters, MAX_CHARS
, to find the remaining character count.
Christopher Mlalazi
Front End Web Development Techdegree Graduate 17,305 PointsHi Kourosh, how do Ido that? Like this? But still this is not working. I now just want to get past this code challenge I will return back to it one day when I know more java to try to analyse it. :)
public getRemainingCharacterCount(){
return MAX_CHARS - mText.length;
}
Kourosh Raeen
23,733 PointsYou're almost there. The method needs a return type which should be int
, so add that after public
. Also you've forgotten the parenthesis for the length()
method.
Christopher Mlalazi
Front End Web Development Techdegree Graduate 17,305 PointsLol, itβs not working
public int getRemainingCharacterCount() {
return MAX_CHARS - mText.length();
}
Kourosh Raeen
23,733 PointsThe problem may actually be related to the constructor. You only need to set mText
in there:
public Tweet(String text) {
mText = text;
}
chase singhofen
3,811 Pointsdepending on where you inserted it, you may need to delete or add some {} these always get me. ALAWAYS. good luck
public int getRemainingCharacterCount() { return MAX_CHARS - text.length();
i put it exactly like this, not messing with any of my braces. took me like 15min.
chase singhofen
3,811 Pointspublic int getRemainingCharacterCount() { return MAX_CHARS - text.length();
worked for me, but i had lots of issues with my braces {}
Christopher Mlalazi
Front End Web Development Techdegree Graduate 17,305 PointsChristopher Mlalazi
Front End Web Development Techdegree Graduate 17,305 PointsHi Lawrence thanks that did the trick! Am still new in java and some of these exercises are a bit tough for me but hopefully with time I will catch up!