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 trialStephanie Walker
4,158 PointsJava challenge - Print out using System.out.printf the color of the new object, using the getColor method.
Hi guys, I'm having a nightmare today, one of those days where nothing seems to make sense, no matter how simple it is! Anyway, I have written out this code in answer to this challenge and it does not like it at all. Can anyone explain where I am going wrong please?
public class Example {
public static void main(String[] args) {
System.out.println("We are going to create a GoKart");
GoKart kart = new GoKart("red");
System.out.printf("The color of the Go Kart is %s\n",
kart.getColor())
}
}
Thanks very much
3 Answers
Andrew Nguyen
2,470 PointsIs it possible to show what the color method looks like? My guess is that the method may be static and you are calling the getColor method wrong? Or the return is wrong. But if you could show me the method or code you have that would be great!
Stephanie Walker
4,158 PointsThat worked! Awesome thank you! Told you I was being dumb haha
Stephanie Walker
4,158 PointsHey, thanks for the quick reply! I have tried what you said but the question specifically asks for System.out.printf and it still didn't like it.
as for the color method I don't know how to retrieve that as it is from a code challenge and does give me the info? Or do I need to add something?
Andrew Nguyen
2,470 PointsAndrew Nguyen
2,470 Pointsactually i think i see your problem. I think your print is wrong. Have you tried,
System.out.println("The color of the Go Kart is " + kart.getColor()) ;
or
you are missing a semi colon at the end of your print.