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 trial

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,012 Points

Can you show me your getColor implementation?

2 Answers

Hendrik Heim
Hendrik Heim
1,012 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,012 Points

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

Show me your GoKart class to identify the problem