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 trialZubeyr Aciksari
21,074 PointsNow in the main method of Display.java, instantiate a new BlogPost. Use System.out.printf to print out "This is a blog p
Hi, i am stuck in here, can someone please help? Thanks!
"Now in the main method of Display.java, instantiate a new BlogPost. Use System.out.printf to print out "This is a blog post: %s" and pass in the newly created BlogPost object to replace the string formatter."
package com.example;
class BlogPost {"This is a blog post: %s"}
import com.example.BlogPost
public class Display {
public static void main(String[] args) {
// Your code here...
System.out.printf(["a"]);
}
}
5 Answers
Zubeyr Aciksari
21,074 PointsI posted the same q again to let u know see my code.
sanjay soni
1,759 Pointspackage com.example; public class BlogPost { }
import com.example.BlogPost;
public class Display { public static void main(String[] args) { BlogPost blogPost = new BlogPost(); System.out.printf("this is a blog post : %s", blogPost);
} }
use the above code its correct!!!
Zubeyr Aciksari
21,074 PointsA bummer shows up, please further help! Thanks!
BlogPost blogPost = new BlogPost();
System.out.printf("This is a blog post: %s" , blogPost);
Rob Bridges
Full Stack JavaScript Techdegree Graduate 35,467 PointsHey Zuebyr, I checked the code again, it compiled just fine.
Are you sure you're doing challenges to lead up to at least the third question?
if not what question are you getting stuck on?
Rob Bridges
Full Stack JavaScript Techdegree Graduate 35,467 PointsLooking into the rest of your code the only thing I could see was that you but a body inside your BlogPost.java class, you actually don't need to declare anything in the class, and I see that you have "This is a blogPost %s" in your BlogPost.java class we're just importing the package, creating the class, but leaving it blank. That class should look like.
package com.example;
class BlogPost {
}
Thanks, that might be what is causing the error.
Rob Bridges
Full Stack JavaScript Techdegree Graduate 35,467 PointsHello!
What this final challenge is wanting us to do is first create a new BlogPost object, since we've imported the package, we should have no problem with this.
It would look like
BlogPost blogPost = new BlogPost();
after that, we can pass in our new BlogPost object into the string, with the blogpost object as the formatted item.
After everything, your code should look similar to below:
import com.example.BlogPost;
public class Display {
public static void main(String[] args) {
BlogPost blogPost = new BlogPost();
System.out.printf("this is a blog post : %s", blogPost);
}
}
Thanks, let me know if this doesn't help.
Matt Bloomer
10,608 PointsI got what you had, I just have a question about it. When you put BlogPost blogPost = new BlogPost();, BlogPost is the type that it returns and blogpost is the name of what you are creating. Since you are creating a new instance of blogpost, that is where the new BlogPost comes from. Is all of that correct?
Rob Bridges
Full Stack JavaScript Techdegree Graduate 35,467 PointsHey Matt, that certainly is. I know it's confusing, we could have called it something like
BlogPost myBlogPost = new BlogPost();
For clarity sake this probably would have been easier.