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

Shayan Khan
Shayan Khan
9,842 Points

Can someone help me please?

I don't understand how to complete this challenge and their saying that somethings wrong with my syntax. Please somebody help me.

Example.java
public class Example {

    public static void main(String[] args) {
        System.out.println("We are going to create a GoKart");
        GoKart kart = new GoKart("red");
        System.out.println("The color of the Go Kart is %s \n" mColor.getColor() ;  
    }
}

2 Answers

rydavim
rydavim
18,814 Points

You've got a couple of syntax errors in your last print line, but you have the right idea.

public class Example {
    public static void main(String[] args) {
        System.out.println("We are going to create a GoKart");
        GoKart kart = new GoKart("red");  

        // System.out.println("The color of the Go Kart is %s \n" mColor.getColor() ;

        System.out.printf("The color of the Go Kart is %s \n", kart.getColor());
        // You're formatting the string, so use printf instead of println here.
        // I'm not sure where mColor came from, but you want to get the color of the kart you just created.

    }
}
Krasimir Georgiev
Krasimir Georgiev
19,146 Points

You should change println to printf if you want to use %s, You need to put a comma after \n" and right now you are getting the colour of a GoKart object named mColor so you should change mColor to kart because that's how you named your GoKart object.

[MOD EDIT - Changed to answer instead of comment so it can be voted on or marked as best. Thank you!]