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 trialMichael Mccarty
1,761 Points"BlogPost: TITLE by AUTHOR"
The question states: Override the toString method from java.lang.Object and make it return the following information: "BlogPost: TITLE by AUTHOR"
My code is: @Override public String toString() { return "BlogPost: \"" + mTitle.toUpperCase() + "\" by " + mAuthor.toUpperCase(); }
What exactly am I doing wrong here?
package com.example;
import java.util.Date;
public class BlogPost {
private String mAuthor;
private String mTitle;
private String mBody;
private String mCategory;
private Date mCreationDate;
public BlogPost(String author, String title, String body, String category, Date creationDate) {
mAuthor = author;
mTitle = title;
mBody = body;
mCategory = category;
mCreationDate = creationDate;
}
@Override
public String toString(){
return "Blog Post: \"" + mTitle.toUpperCase() +"\" by " + mAuthor.toUpperCase();
}
public String getAuthor() {
return mAuthor;
}
public String getTitle() {
return mTitle;
}
public String getBody() {
return mBody;
}
public String getCategory() {
return mCategory;
}
public Date getCreationDate() {
return mCreationDate;
}
}
2 Answers
andren
28,558 PointsThis is a case of the task being very picky, and also a case of it being quite misleading.
There are two issues:
You start your string with "Blog Post" instead of "BlogPost" as one word which is what the challenge shows in its example.
Even though you would certainly think so based on the message example, the challenge does not actually want the post title and author to be capitalized.
If you change "Blog Post" into one word and remove the capitalization code like this:
@Override
public String toString(){
return "BlogPost: \"" + mTitle +"\" by " + mAuthor;
}
Then your code will be accepted.
Michael Mccarty
1,761 PointsThank you!