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

Mark Stoelinga
Mark Stoelinga
746 Points

[SOLVED] Stuck with creating a new GoKart object with parameter.

I can't seem to figure this out. I think this code should be right, but something is obviously wrong or I would pass the test :)

Example.java
public class Example {

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

    }
}
Mark Stoelinga
Mark Stoelinga
746 Points

Fixed it after deleting the space after "new GoKart (". Works! Sorry to bother you guys :)

Shivam Patel
Shivam Patel
860 Points

Mark, I am struggling with the same challenge - I am getting a try again message - my code looks the same as yours but feel that the task before hasn't transferred through. What error message were you seeing?

Mark Stoelinga
Mark Stoelinga
746 Points

Hey Shivam,

That was the weird thing, there were no error messages in the "preview" window, so the code should work(I think). maybe there is some peculiarity in the check treehouse with their "right" code comparison. I also played around with the "redKart" name, and changed it into "gokart" all lower case letters. Hope this helps! Good luck :)

Shivam Patel
Shivam Patel
860 Points

Thanks for your reply Mark - managed to complete the Challenge.

Ken Alger
Ken Alger
Treehouse Teacher

Edited title to [SOLVED]

Gentlemen;

In terms of what you name your cart, it really shouldn't matter as long as you stay away from Java defined words. So naming your cart String, or int for example won't work. However, using descriptive names like redKart, reallySuperFastKart, markKart, shivamKart are all acceptable. The important thing is the syntax

Think of creating objects in Java. For this example what are we creating, a GoKart object named whatever. Let's call it blueKart, so we need to tell Java "Hey we are creating a new GoKart object, going to name it blueKart and since you need to know the color, we're going to give it a value of blue." In Java, as you know from the course and challenge, that looks like:

GoKart blueKart = new GoKart("blue");

Great job on making it through this one and figuring out the syntax issues, they can keep even the most experienced developers occupied for long periods of time.

Happy coding and welcome to Treehouse!

Ken

3 Answers

Hi, I have the same issue, I tried the same code but i get a try again message while there is no error shown.

Ken Alger
Ken Alger
Treehouse Teacher

Abdul;

Welcome to Treehouse!

Will you post the code you are using on a new forum post? Let's see if we can't get this resolved for you.

Ken

Dean Onizuka
Dean Onizuka
4,753 Points
System.out.printf("The GoKart is %s", redKart.getColor() );

that line by itself in the code above should not work. yet it passes the exercise? wouldnt you always get an error because getColor has not be defined anywhere. In the previous examples in this lesson we had a seperate file where the getCharacterName was defined with the mCharacterName and all that... yet here we are doing something completely different.

i think thats where lots of the confusion comes from. or am i missing something here?

Hi Dean,

Thank you for clarification. Indeed, this is what confuses me, but still i can't pass the exercise with this code. There is no description for the error i receive. It says "Bummer Try Again".

I don't know how to move forward from this exercise.