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

Abe Daniels
PLUS
Abe Daniels
Courses Plus Student 2,781 Points

Is there a term for too many terms?

I'm confused as to what exactly a Constructor is. Meanwhile I'm sorting through my arsenal of methods to come up with the proper answer. If I could get a good explanation as to when to use certain methods, I would be happier with that than the answer. "Teach a man to fish... etc. etc."

GoKart.java
public class GoKart {
  //unexposed color
  private String mColor;
  //an accessible, absolute, integer
  public static final int MAX_BARS = 8;
 //unexposed var that returns nothing
  private void GoKart(int mBarsCount) {
    mBarsCount = 0;
  }
  //constructor???
  public GoKart(String color) {
    mColor = color;

  }
  //get and return of color
  public String getColor() {
    return mColor;
  } 
}

2 Answers

Nearly - I'll try to answer below:

public class GoKart {
  // private mamber variable for each instance of the GoKart class - accessible by getter and setter only
  private String mColor;


  // an accessible, absolute, integer - pretty much, yes. No idea why this isn't private

  public static final int MAX_BARS = 8;

 //unexposed var that returns nothing - ?? This is a constructor as its name is the same as the class yet it is private. That's not right? Even if the private bit is right, why would it take a parameter and then set the same thing to zero inside the method - this isn't right. 

  private void GoKart(int mBarsCount) {
    mBarsCount = 0;
  }
  //constructor??? - Yes! A constructor that needs a color parameter to create a GoKart! 
  public GoKart(String color) {
    mColor = color;
  }

  //get and return of color - a getter method for the mColor member variable
  public String getColor() {
    return mColor;
  } 
}

There's probably more questions than answers there! There's stuff in there that isn't correct but let's work through it in turn to fix it all.

Steve.

Abe Daniels
Abe Daniels
Courses Plus Student 2,781 Points

I got that portion of the question figured out now. I have now moved onto it asking me to, "Add a private (private) uninitialized (static?) field (mBarsCount), to store the CURRENT amount of energy bars. (I'm assuming that means i'll have to put getBarsCount in the constructor since "current" means it will be changing as time passes.) It then asks me to initialize (no idea if this is a keyword for some sort of function, or literal.) it to zero in the constructor. This raises red flags to me. I don't understand how I would make it get current information, but at the same time assign it an absolute value (0.)

Abe Daniels
Abe Daniels
Courses Plus Student 2,781 Points

uninitialized in this set of directions means either, private mBarsCount(); OR private static mBarsCount(somethingshouldgohere) ... again, at least to me x)

Can you break that down into some questions, Abe? There's lots of assumptions, you say, in there. Let's cut this right down to what you want to know rather than you half answering your own question. Does that make sense?

I'd rather do a single answer that you can rely on rather than explaining through a load of assumptions that might not clarify what you want to know.

You just need some clarity on the jargon - but you need to ask the questions (minus your assumptions) so you can have the answer for each one.

Make sense?

Steve.

Abe Daniels
PLUS
Abe Daniels
Courses Plus Student 2,781 Points

I think I've got the right string of words! How would I go about storing a number in a field, naming it, and then initializing it within a constructor? Thanks for all of your help :))

Abe Daniels
Abe Daniels
Courses Plus Student 2,781 Points

I figured it out! It just took some comparing to the code used in the video, and now i FULLY understand what's going on! TeamTreeHouse > MAX_INT