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 trialBenjamin Ing
910 Pointsunsure on what the comments are asking me to do
i dont understand the comments in the example.java
public class ForumPost {
private User mAuthor;
private String mTitle;
private String mDescription;
public ForumPost(User user, String title, String description)
{
mAuthor = user;
mTitle = title;
mDescription = description;
}
public User getAuthor() {
return mAuthor;
}
public String getTitle() {
return mTitle;
}
public String getDescription(){
return mDescription;
}
// TODO: We need to expose the description
}
public class User {
private String mFirstName;
private String mLastName;
public User(String firstName, String lastName) {
// TODO: Set the private fields here
mFirstName = firstName;
mLastName = lastName;
}
public String getFirstName(){
return mFirstName;
}
public String getLastName(){
return mLastName;
}
}
public class Forum {
private String mTopic;
public Forum(String topic)
{
mTopic = topic;
}
public String getTopic() {
return mTopic;
}
public void addPost(ForumPost post) {
System.out.printf("New post from %s %s about %s.\n",
post.getAuthor().getFirstName(),
post.getAuthor().getLastName(),
post.getTitle());
*/
}
}
public class Example {
public static void main(String[] args) {
System.out.println("Starting forum example...");
if (args.length < 2) {
System.out.println("first and last name are required. eg: java Example Craig Dennis");
}
Forum forum = new Forum("Java");
// Take the first two elements passed args
User author = new User();
// Add the author, title and description
ForumPost post = new ForumPost();
forum.addPost(post);
}
}
1 Answer
Dan Johnson
40,533 Points"Take the first two elements passed args" refers to the command line arguments that are supplied. These are passed in to main as args, where args[0]
is expected to be the first name, and args[1]
is expected to be the last name. You can use these to create the User
author.
For the ForumPost
itself you just need to pass in the author that you just created and then pick a title and description of your choosing.