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 Java Objects (Retired) Meet Objects Creating New Objects

kalyada leosrisook
PLUS
kalyada leosrisook
Courses Plus Student 17,855 Points

I'm stuck in this last Gokart challenge. someone please help!

Hi, I've been stuck in this last challenge where you need to apply the getColor method. When I use the method I got an error saying that:

'method getColor in class GoKart cannot be applied to given types; System.out.printf("The go kart color is %s\n", gokart.getColor("red"));'

What does this mean? Can anyone explain? Thank you in advance...

Example.java
public class Example {

    public static void main(String[] args) {
        System.out.println("We are going to create a GoKart");
        GoKart gokart = new GoKart("red");
        System.out.printf("The go kart color is %s\n", gokart.getColor("red"));



    }
}
Hendrik Heim
Hendrik Heim
1,011 Points

Can you show me your getColor implementation?

2 Answers

Hendrik Heim
Hendrik Heim
1,011 Points
public class GoKart {

    private String _color;

    public GoKart(String color){
    _color = color;
    }

  public String getColor(){

    return _color;
  }

}

is your GoKart class "equal" to this?

Notice, that you your _color field ist String, so is your Constructor Parameter and your method should also return a String.

kalyada leosrisook
kalyada leosrisook
Courses Plus Student 17,855 Points

Yeah, mine kinda look like your, except that I use ' mColor instead of _color. Is that the problem? what does _ means?

Hendrik Heim
Hendrik Heim
1,011 Points

_color / mColor is just a variable name. So it is irrelevant.

Show me your GoKart class to identify the problem