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 trialPraveen Rai
2,217 PointsI can not find way to return an italic string. Is there some easy way to do this?
In Override the toString function, question requires you to return text "BlogPost: TITLE by AUTHOR" where TITLE and AUTHOR are in italic. What is the way to return these specific words in a sentence in italic?
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 "BlogPost: TITLE by AUTHOR";
}
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;
}
}
1 Answer
andren
28,558 PointsThat's not actually what the challenge is looking for. The words are written in italic in the example to represent that they are meant as placeholders, not literal parts of the string. The challenge does not want you to write "TITLE" and "AUTHOR" in the string, they want you to place the title and author of the BlogPost into the string instead.
So if the BlogPost's mTitle
variable was set to "Test Post" and mAuthor
was set to "Andren" for example then the string returned would look like this: "BlogPost: Test Post by Andren"
.
To answer your actual question though, strings can't be made italic, or bold or anything else like that. String is a class that is only concerned with storing text, formatting the text is up to whatever method you use to render the string to the screen.
Praveen Rai
2,217 PointsPraveen Rai
2,217 PointsThanks! I did not understand the challenge correctly. Now, I am able to complete the challenge.