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
james white
78,399 PointsJava Objects, Delivering the MVP, Stage 4, Wrapping Up, Challenge Task 3 of 4
Challenge Task 3 of 4
Alright so now let's focus on ForumPost. It's going to need a constructor that takes a User author a String title and a String description. Also please add the getter for mDescription.
Here's all it has for ForumPost.java at the start of the challenge:
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
}
//So I figured this would pass the challenge,
//but it does not:
public class ForumPost {
private User mAuthor;
private String mTitle;
private String mDescription;
public User getAuthor() {
return mAuthor;
}
public String getTitle() {
return mTitle;
}
//Added:
public ForumPost(User author, String title, String description){
}
// TODO: We need to expose the description
public String getDescription(){
return mDescription;
}
}
Do I need to do something else inside the ForumPost constructor?
What that might be...?
1 Answer
james white
78,399 PointsThis is so stupid and annoying!
The challenge didn't say that I needed to set anything inside the constructor,
but just out of sheer frustration I tried adding:
mAuthor = author;
mTitle = title;
mDescription = description;
//To make the whole thing:
public class ForumPost {
private User mAuthor;
private String mTitle;
private String mDescription;
public User getAuthor() {
return mAuthor;
}
public String getTitle() {
return mTitle;
}
public ForumPost(User author, String title, String description){
//Shouldn't have to do this, but..
mAuthor = author;
mTitle = title;
mDescription = description;
}
// TODO: We need to expose the description
public String getDescription(){
return mDescription;
}
}
.and lo and behold I got lucky and it passed!
This challenge is way to long and hard,
but on to 4 of 4.
This forum post helped me through Challenge 4: https://teamtreehouse.com/forum/stage-4-wrapping-up-challenge-task-4-of-4
However be aware when the challenge says: "Finally, uncomment the addPost method in Forum.java. Then for the last task, uncomment the main method in Example.java"
..that is DOES NOT mean uncomment everything!
If you remove ALL the double slashes for these lines in Example.java it's going to cause issues:
// 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);
Overall this challenge left me exhausted and defeated.
With the completion of Java Objects, my Java points jumped from 275 to 710..I guess that's something.
```html
<br>
```
I wish the Java Objects course would have had a little more of a Deep Dive on harnessing the power of classes in Java to do interesting and powerful things.
I was hoping to explore a bit of OOP (object oriented programming).
Doesn't java use anything like: Encapsulation, Inheritance, Abstraction, Polymorphism
Also..has no one at Treehouse heard about Java's Swing and AWT graphical/GUI oriented widget toolkits (to say nothing of Java2D or LWJGL).
I took the CS106 online Stanford course (which teaches java).
It has a jar (Java archive) for Karel the robot that is very user friendly way for people to "ease in" to learning java.
Explanatory pdf: http://web.stanford.edu/class/cs106a/book/karel-the-robot-learns-java.pdf
Setup instructions: http://arnaudbertrand.com/playing-with-stanfords-karel-the-robot-on-a-standard-eclipse/
Maybe Treehouse can do something similar with Mike the Frog.
Anyway...I guess I'll have to wait patiently for Java Objects 2 (or some other non-Android-specific Java courses) to come out.
Craig Dennis
Treehouse TeacherCraig Dennis
Treehouse TeacherWe are planning on doing a deeper dive into objects regarding abstraction, polymorphism, interfaces and encapsulation as well as the standard collections in the upcoming Java Data Structures course.
Glad you stuck with it!
Thanks for the feedback, I'll work on making the challenge more specific!