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

data type user?

In Java course after you finish the hangman project and when you are doing the coding challenge:

Challenge Task 3 of 4 Okay so now let's work on ForumPost.java

Add a constructor to ForumPost which accepts a User named author, a String named title, and another String named description. Initialize the corresponding private fields.

You can create your own data types? take a look at the code below. I'm not understanding "User" set as a data type like String or int or boolean - Never heard about User and tried to google this and all I got was that you can create your own data types. If this is the case why wasn't this covered in the java course up to this point?

public class ForumPost {
  private User author;// <---- ???? what the heck is this User data type? 
  private String title;
  private String description;

  // TODO: add a constructor that accepts the author, title and description

  public ForumPost(User author, String  title, String description){
    this.author = author;
    this.title = title;
    this.description = description;
  }

1 Answer

Zhaopeng Wang
seal-mask
PLUS
.a{fill-rule:evenodd;}techdegree seal-36
Zhaopeng Wang
Full Stack JavaScript Techdegree Graduate 32,210 Points
  • It comes from Step 2, User.java
public class User {
  // TODO: add private fields for firstName and lastName
  private String firstName;
  private String lastName;

  public User(String firstName, String lastName) {
    // TODO: set and add the private fields
    this.firstName = firstName;
    this.lastName = lastName;

  }

  // TODO: add getters for firstName and lastName
  public String getFirstName (){
    return this.firstName;
  }

  public String getLastName(){
    return this.lastName;
  }

}