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) Harnessing the Power of Objects Methods and Constants

Return Type Required???

Here is the code:

when I run it it tells me that there is a return type required .

public class GoKart {
  public static final int MAX_BARS = 8;
  private int mBarsCount;
  private String mColor;


  public mColor(String color) {
    mColor = color;
  }

  public mBars(String MAX_BARS) {
    mBarsCount = 0;
  }

  public String getColor() {

    return mColor;
  } 
}

code

2 Answers

It worked! Thanks! :)

Grigorij Schleifer
Grigorij Schleifer
10,365 Points

Nice to hear it!

Keep on rocking :)

Grigorij Schleifer
Grigorij Schleifer
10,365 Points

Hi Thomas,

public class GoKart {
// your fields are perfect
// no need to worry about
  public static final int MAX_BARS = 8;
  private int mBarsCount;
  private String mColor;

  public GoKart(String color) {
    mColor = color;
    mBarsCount = 0; // <<<<<<<<<<<< initialize mBarsCount to 0 inside the constructor;
  }

  public String getColor() {
    return mColor;
  } 

// here we need to create a charge() method that
// increments mBarsCount to MAX_BARS (8)
// this method returns no value, so it is void
  public void charge() {

// so mBarsCount is equals to your constant variable 
// you declared in the Task 1
  mBarsCount = MAX_BARS;
  }
}

Your code:

// I think here you are trying to create a constructor
// the name of the constructor must be the same as of the class (GoKart, not mColor)
  public mColor(String color) {
    mColor = color;
  }

  public mBars(String MAX_BARS) {
// this should be in the constructor
// no need to create a new method 
// and give it a parameter MAX_BARS
    mBarsCount = 0; 
  }

I hope I could help a little bit

Let me know if you need more help

Marry Christmas from germany

Grigorij