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

Kyle Dudley
Kyle Dudley
604 Points

Task one is no longer passing.

Idk why anymore.

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


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

  public boolean isBatteryEmpty() {
    return barCount == 0;
  }


  public String isFullyCharged() {
      if ( barCount == 8 ) {
        console.printf("Full!");
      } 
        }
      }
  }  


  public String getColor() {
    return color;
  }

  public void charge() {
    barCount = MAX_BARS;
  }
}

The error message is quite unintuitive - I also had a problem with it. If you click "GO TO TASK ONE" the code from task two gets replaced by the working code from task one. What you have to do is:

  1. Before clicking "GO TO TASK ONE" copy your code from task two.
  2. Click "GO TO TASK ONE"
  3. Paste the code from task two to the task one window.
  4. Execute the code and at that point you will get the message with proper explanation, why your code from task two does not pass task one requirements anymore.

I hope the explanation is clear enough :)

1 Answer

John McCartan
John McCartan
549 Points

public boolean isFullyCharged() { return barCount == MAX_BARS; }

From what I understand, the barCount needs to equal the max amount of bars.

Also from looking, you have many '{}' these can mess up the code, hope this has helped.