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 trialSaurabh B
Courses Plus Student 2,880 PointsPrint out using System.out.printf the color of the new object, using the getColor method. Please help me
My code is:
public class Example {
public static void main(String[] args) {
System.out.println("We are going to create a GoKart");
GoKart GooKart = new GoKart("blue");
private String x = GooKart.getColor();
System.out.println(x);
}
}
// What is wrong with this?
public class Example {
public static void main(String[] args) {
System.out.println("We are going to create a GoKart");
}
}
3 Answers
ISAIAH S
1,409 PointsTry this:
public class Example {
public static void main(String[] args) {
GoKart mColor = new GoKart("red");
System.out.println("We are going to create a new GoKart.");
System.out.printf("The color of the GoKart is %s.", mColor.getColor());
}
}
Saurabh B
Courses Plus Student 2,880 PointsI understood all of your points but the way I declared string then passed the color value to it then printed it using system.out.println function. What is wrong with this way as we are only considered with the output. Is my systax wrong?
Saurabh B
Courses Plus Student 2,880 PointsI understood all of your points but the way I declared string then passed the color value to it then printed it using system.out.println function. What is wrong with this way as we are only considered with the output. Is my systax wrong?
Anthony Branze
4,887 Pointssorry i didnt look over my answer well enough before hand. So you are close but your syntax is slghtly off. to create the object all we have to do is specify the object and its color
GoKart goKart = new GoKart ("red");
System.out.printf(goKart.getColor());
is What how i did it
Saurabh B
Courses Plus Student 2,880 PointsI understood all of your points but the way I declared string then passed the color value to it then printed it using system.out.println function. What is wrong with this way as we are only considered with the output. Is my systax wrong?
Broderic Crowe
1,549 PointsLOL. 45 minutes of syntax refusal cause I didn't add the the '( )' at the end of getColor. I thought I needed to make a getColor string, forgot its a method already.
luis martinez
2,480 Pointsluis martinez
2,480 Pointshear is the answer change the goo-kart to color because is a little confusing.
public class Example {
}