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

AYMERIC FIGEROU
AYMERIC FIGEROU
3,748 Points

Please create a new GoKart object. As you know it takes a single parameter, color.

Hello TreeHouse Community,

Several errors have been detected, and i got hard time detecting them. English is a second language, so this post may contained orthographics mistakes as well.

My main issue is with the line color.getColor. since color=mColor, then, Why would we have to do it two time?

I hope i have been enough clear to be understandable,

thanks for your answer,

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.print.out("Fuck it, dope it %s\n", color.getColor());                               
    }
        public String GoKart {
          private string mColor; 

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

          public String getColor () {
          return mColor;
    }

        }

2 Answers

Michael Hess
Michael Hess
24,512 Points

Hi Aymeric,

It looks like you're really close, but there are a few things that you may want to change. We can assume that the GoKart class has already been created -- so there is no need to create a GoKart class. The challenge has asked us to use System.out.printf. Please see the following code:

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("%s", gokart.getColor());
    }
  }

The %s is a place holder for a variable in the printf statement. Then we simply call goKart.getColor() to get the color we passed in via the constructor when we declared the goKart object in task 1.

If you have any further questions don't hesitate to ask! Hope this helps!