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

Shafique Mohammed
seal-mask
.a{fill-rule:evenodd;}techdegree
Shafique Mohammed
Front End Web Development Techdegree Student 13,625 Points

Can anyone help Print out using System.out.printf the color of the new object, using the getColor method.

Can anyone help me and let me know were i have gone wrong Print out using System.out.printf the color of the new object, using the getColor method.

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(getColor());

    }
}
Dennis Addo
Dennis Addo
Courses Plus Student 2,943 Points

try using the %s for the getColor(), System.out.printf(%s %n,getColor()); the printf is a formatting command so you need some formatting settings when using it. try this and let see.

4 Answers

Dennis Addo
Dennis Addo
Courses Plus Student 2,943 Points

Can you try and call the getColor() method on the new created object redKart. because i think that is the method you want to get the color. so System.out.printf(%s %n, redKart.getColor())

Shafique Mohammed
seal-mask
.a{fill-rule:evenodd;}techdegree
Shafique Mohammed
Front End Web Development Techdegree Student 13,625 Points

public class Example {

public static void main(String[] args) {
 GoKart redKart = new GoKart("Red");
  System.out.printf(%s %n, redKart.getColor())
}

}

Still coming with error messages

Dennis Addo
Dennis Addo
Courses Plus Student 2,943 Points

can you try and paste the error message here. so that we know what kind of error we are dealing with me.

Dennis Addo
Dennis Addo
Courses Plus Student 2,943 Points

ok can you ignore the printf command and use System.out.print(), and did the task ask that you print the color or you just need to create a new GoKart object?

if not then you have to check that the getColor() method exit. because it seems the getColor method is the problem here.