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 Harnessing the Power of Objects Computed Properties

Ahmad Khaled
Ahmad Khaled
13,026 Points

Computed Properties!

I don't clearly understand this challenge!

  • How am I supposed to return True if the amount of bars equal zero?
  • And false if the amount of bars equals (1-12)?

I find it quite humiliating that I don't even get the question :(

class GoKart {
  public static final int MAX_BARS = 8;
  private String color;
  private int barCount;

  public GoKart(String color) {
    this.color = color;

  public String getColor() {
    return color;

  public void charge() {
    barCount = MAX_BARS;

1 Answer

28,558 Points

Through a comparison. You learned about the == equal operator back in the Java Basics course which is used to compare two things, using that you can find out if barCount is equal to 0.

The result of a comparison is a Boolean value. In other words if the result of a comparison is true (IE the two things are equal in the case of the equal operator) then it will return the boolean true, if the result of the comparison is false, then it returns false.

So to illustrate:

boolean example = 5 == 5;
// "example" will equal "true" since 5 is equal to 5

boolean example2 = 5 == 1;
// "example2" will equal "false" since 5 is not equal to 1

// ...

return 5 == 2;
// You can also directly return the result of a comparison, you don't have to assign it to a variable.

So all you need to do is return the result of using the equal operator to compare barCount to 0. You don't need to explicitly check for values 1-12 since anything other than 0 should return false.

I would recommend you try again with those hints in mind. If you still can't solve it I can post the answer for you.

Ahmad Khaled
Ahmad Khaled
13,026 Points

I am even more ashamed after this answer :(

It's so simple that got me so Mad! passed this coding challenge though o/