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

Java

This no work.... need help...pls....

Example.java
public class Example {

    public static void main(String[] args) {
        System.out.println("We are going to create a GoKart");
        System.out.printf("The color of the kart is %s", redKart.getColor());
        System.out.printf("The color of the kart is %s", myKart.getColor());
    }
}

7 Answers

Kevin Faust
Kevin Faust
15,353 Points

Hey Ary,

What this challenge is asking you to first do is create a GoKart object. Do you remember how to do that? It says that we already have a GoKart class. So we build that GoKart object and pass it a color string as a constructor value. It would look like this:

      GoKart mykart = new GoKart("red");

We then call the getColor() method on that object. The object we create above has a name of mykart. we do this:

System.out.printf(mykart.getColor());

completed code in case your confused:

public class Example {

    public static void main(String[] args) {
        System.out.println("We are going to create a GoKart");
      GoKart mykart = new GoKart("red");
      System.out.printf(mykart.getColor());
    }
}

Kevin

Kevin Faust
Kevin Faust
15,353 Points

Sorry i typed it in wrong:

public class Example {

    public static void main(String[] args) {
        System.out.println("We are going to create a GoKart");
      GoKart mykart = new GoKart("red");
      System.out.printf(mykart.getColor());
    }
}

This one should work

public class Example {

public static void main(String[] args) {
    System.out.println("We are going to create a GoKart");
  GoKart gokart = new myKart("red");
  System.out.printf(mykart.getColor());
}

}

still no work to me... sorry

the teacher knows a lot about Java, but have no idea what being didactic teacher ...

thanks for the help Kevin, I will not do more tasks now will only see the videos ...

Kevin Faust
Kevin Faust
15,353 Points

no problem. i hope my explanation made a little sense to you. Dont worry just keep reviewing, learning, and studying and you will be very good one day

Grigorij Schleifer
Grigorij Schleifer
10,365 Points

Hey Ary,

I am sure that not-doing the challenges is nor right. You are right, many of the challenges are often frustration and the questions are difficult. But donΒ΄t give up. ItΒ΄s a hard time and you need patience.

Ask here in forum, we will help you.

I am doing the java course again. Try to manage the challenges and resolve them. Read a lot here in the forum. And slowly understand more.

I am sure ... you need challenges :)

Grigorij

about Java and java script

thank you....