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

pinar
pinar
2,329 Points

Try Again! problem

I keep getting "Try again" error about my second task. it doesn't give me a specific error message. When I preview the code it doesn't show anything. Here is my first task code public class GoKart { private String mColor; public GoKart(String color) { mColor = color; } public String getColor() { return mColor; } } Thank you

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("blue");
      System.out.printf("let's dye a Gokart %s\n.",kart.getColor());
    }
}

4 Answers

Michael Hess
Michael Hess
24,512 Points

Hi Pinar,

I was able to pass both tasks using your code. I had to comment out the printf statement to pass task 1 after copy & pasting.

public class Example {

    public static void main(String[] args) {
        System.out.println("We are going to create a GoKart");
        GoKart kart = new GoKart("blue");
      // uncomment printf after task1 is passed
 //    System.out.printf("let's dye a Gokart %s\n.",kart.getColor());  
    }
}

If you have any questions I will be happy to answer them.

Michael Hess
Michael Hess
24,512 Points

If you copy and paste you need to make sure the printf (task 2) is commented out -- or you'll get an unspecified error on task 1. Uncomment the printf line after task 1 is completed.

The \n works though. But, if you paste the whole code block -- you'll get an unspecified error on task 1 of the challenge.

The code is correct, but the way the challenge was designed is causing the error -- if that makes any sense.

pinar
pinar
2,329 Points

Dear Michael, changing my answer for part 1 worked! Thank you so much for helping me! A little help really makes a big difference :) And thank you for your support - I'm very new at this, so it's really nice to hear encouragement.

Michael Hess
Michael Hess
24,512 Points

No problem -- I'm glad that I could help!

pinar
pinar
2,329 Points

Hi Michael, Thank you very much for helping. However, I took the \n out of my code and İ still get the error. İ even copy-pasted your code in, and it doesn't pass. Hmm... this is very strange.

You were very close:

Example.java
// For the first task:
public class Example {
    public static void main(String[] args) {
      GoKart goKart = new GoKart("blue");
      System.out.println("We are going to create a GoKart");

      // And the second:
      System.out.printf("The color of the GoKart is %s", goKart.getColor());
    }
}

So I guess you didn't need the 'System.out.printf("let's dye a Gokart %s\n.",kart.getColor());' until the second task.

Hope it helps!

ISAIAH S

Michael Hess
Michael Hess
24,512 Points

What Pinar wrote is corrrect -- it's just the way the challenge was designed. Pinar's code is correct. I copy & pasted Pinar's code to check it.

Nothing about the code needs to be changed.