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 Java Objects Delivering the MVP Forum

Adam Imiolo
Adam Imiolo
762 Points

Wrapping Up Challenge: Task 2 of 4 - issue with names

Is it really necessary to name private variables 'firstName' and 'lastName'? I get this error when I attempt to use format 'mFirstName' and 'mLastName'. I got to Task 4 / 4 and get an error saying task 2 is no passing. Really confused now thinking I will need to rework everything. What am I doing wrong really? Spent around an hour on the forum and see everyone is doing just fine using 'mFirstName' sort of thing.

Bummer! Make sure you add a private String field to the User class named firstName

Forum.java
public class Forum {
  private String topic;
  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());

  }
}
User.java
public class User {
  private String mFirstName;
  private String mLastName;

  public User(String firstName, String lastName) {
    mFirstName = firstName;
    mLastName = lastName;
  }
  public String getFirstName(){
      return mFirstName;
   }
  public String getLastName(){
      return mLastName;
   }
}
ForumPost.java
public class ForumPost {
  private User mAuthor;
  private String mTitle;
  private String mDescription;

  public User getAuthor() {
    return mAuthor;
  }

  public String getTitle() {
    return mTitle;
  }

  // TODO: We need to expose the description
Main.java
public class Main {

  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");
    User author = new User(args[0], args[1]);
    ForumPost post = new ForumPost(author, "Java Is Cool", "Wahoo!");
    forum.addPost(post);
  }

}