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

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.