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

Task 1 is no longer passing.

For task 1, the following code works; public boolean isBatteryEmpty(){ return barCount==0; }

For task 2, after I have added the following and made no changes on other parts, it said task 1 no longer passing. public boolean isFullyCharged(){ return barCount==MAX_BARS; }

Is there anyone knowing what is happening?

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 String getColor() {
    return color;
  }

  public void charge() {
    barCount = MAX_BARS;
  }
  public boolean is FullyCharged(){
    return barCount==MAX_BARS;}

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

1 Answer

Jennifer Nordell
seal-mask
STAFF
.a{fill-rule:evenodd;}techdegree
Jennifer Nordell
Treehouse Teacher

Hi there! You're doing great, actually! In fact, you have the working function it asks for for Step 2. The problem is that you've also duplicated it into another function that doesn't work. Keep in mind that variable names and function names may not contain spaces. In your first attempt at the function you typed is FullyCharged instead of isFulllyCharged. This results in a syntax error which is prohibiting your code from compiling and why you're receiving the "Task 1 is no longer passing". This is a common message when a syntax error has been introduced.

If I remove your incorrectly named function, your code passes both steps! Hope this helps! :sparkles:

class GoKart {
  public static final int MAX_BARS = 8;
  private String color;
  private int barCount;
public boolean isBatteryEmpty(){
return barCount==0;
}
  public boolean isFullyCharged(){
    return barCount==MAX_BARS;}

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

  public String getColor() {
    return color;
  }

  public void charge() {
    barCount = MAX_BARS;
  }

  }
}

I have changed it, but it still says the same error.

Jennifer Nordell
seal-mask
.a{fill-rule:evenodd;}techdegree
Jennifer Nordell
Treehouse Teacher

Hi again! Somehow, when you changed it, you managed to not remove an ending closed curly brace. If I remove the last closed curly brace }, your code passes! :sparkles: