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 trialSarah Parker
2,831 Pointscan't preview any syntax errors - not sure whats wrong here
when i click preview i dont see any syntax errors, so I have no clue why this isnt working and is resulting in compiler/syntax errors..
public class Forum {
private String mtopic;
// TODO: add a constructor that accepts a topic and sets the private field topic
public setTopic(String topic) {
mtopic = topic;
}
public String getTopic() {
return mtopic;
}
public void addPost(ForumPost post) {
System.out.printf("A new post in %s topic from %s %s about %s is available",
mtopic,
post.getAuthor().getFirstName(),
post.getAuthor().getLastName(),
post.getTitle()
);
}
}
public class User {
// TODO: add private fields for firstName and lastName
private String mfirstName;
private String mlastName;
public User(String firstName, String lastName) {
// TODO: set and add the private fields
mfirstName = firstName;
mlastName = lastName;
//new User(firstName, lastName);
}
// TODO: add getters for firstName and lastName
public String getFirstName() {
return mfirstName;
}
public String getLastName() {
return mlastName;
}
}
public class ForumPost {
private User mauthor;
private String mtitle;
private String mdescription;
// TODO: add a constructor that accepts the author, title and description
public ForumPost(User author, String title, String description) {
mauthor = author;
mtitle = title;
mdescription = description;
}
public User getAuthor() {
return mauthor;
}
public String getTitle() {
return mtitle;
}
public String getDescription() {
return mdescription;
}
}
public class Main {
public static void main(String[] args) {
System.out.println("Beginning forum example");
if (args.length < 2) {
System.out.println("Usage: java Main <first name> <last name>");
System.err.println("<first name> and <last name> are required");
System.exit(1);
}
Forum forum = new Forum("Java");
// TODO: pass in the first name and last name that are in the args parameter
User author = new User(args[0], args[1]);
// TODO: initialize the forum post with the user created above and a title and description of your choice
ForumPost post = new ForumPost(author, "my title", "my description");
forum.addPost(post);
}
}
2 Answers
Dino Šporer
5,430 PointsInstead of mtitle naming convention, use something like this.var = var in constructor. Hope that works !
Sarah Parker
2,831 PointsI tried that originally and it didn't work, so switched to m convention! I wish it would tell me where the syntax errors are!