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 trialDejan Buric
12,560 PointsI'm getting an error
Hello,
I need to "Print out using System.out.printf the color of the new object, using the getColor method.", but when I type my code, I'm getting lot of errors. Can someone explain me what I need to do. Thanks
public class Example {
public static void main(String[] args) {
System.out.println("We are going to create a GoKart");
GoKart parameter = new GoKart("color");
public String getColor() {
return parameter
}
System.out.printf(GoKart.getColor);
}
}
3 Answers
Kyle Salisbury
Full Stack JavaScript Techdegree Student 16,363 PointsI see a few issues that I can help with.
1.) Your constructor looks great. I would just fix a few things real quick. Right now you have Java GoKart parameter = new GoKart("color");
which is great except for two things. The first isn't a big deal, I would just change the word parameter to something that is a word closer to the context, like vehicle or kart. The next thing is the word "color" you have in the parameter. It's asking for you to literally type in the color you want like red, blue, or purple. So your constructor might look something like this:
Java GoKart kart = new GoKart("red");
2.) Your getColor method should be in a different class. That is the point of the constructor in the first place. To reach out and connect to the other class or "page". So for it to be on the same page doesn't make a lot of sense. Plus it should return the member variable of the color. So instead of parameter it should say return mColor.
3.)Good idea with the printf but right now you have Java System.out.printf(GoKart.getColor);
which is just slightly off. You got the right idea with the getColor, but it's not GoKart.getColor, it should be (parameter.getColor) or if you were to use my example above it would be (kart.getColor).
Let me know if you have any further questions.
David Lacedonia
13,627 PointsWhen you create your GoKart object, you have to use a more significant name. In this case "kart"
Gokart kart = new GoKart("Dejan kart");
Your new object (kart) already have a method that return the color, and is "getColor()", so you do...
System.out.printf( kart.getColor() );
Anthony Branze
4,887 PointsYou're right there, just like the others have said, rename your gokart Kart and pass the color you want your kart to be then call system.out.printf(kart.color)