Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

Java

Stephanie Walker
Stephanie Walker
4,158 Points

Java 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
Andrew Nguyen
2,470 Points

Is 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!

Andrew Nguyen
Andrew Nguyen
2,470 Points

actually 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.

Stephanie Walker
Stephanie Walker
4,158 Points

That worked! Awesome thank you! Told you I was being dumb haha

Stephanie Walker
Stephanie Walker
4,158 Points

Hey, 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?