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

Hi guys in this task he said you don't pass task 1 but i actually i pass it

The task need to make two methods " isEmpty() " to check the barCount is equal to 0 or not and i did with no problem and the second method "isFully()" to check the barCount is equal to MAX_BARS and also i did it but there is error "Yo don't pass task 1" !!

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

   public boolean isFullyCharged(){
    retrun barCount != MAX_BARS ;
  }


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


  public String getColor() {
    return color;
  }

  public void charge() {
    barCount = MAX_BARS;
  }

 public boolean isBatteryEmpty(){
  if( barCount == 0) 
    return true ;
   else 
     return false ;
  }


}

3 Answers

Patrik Horváth
Patrik Horváth
11,110 Points

i dont see in your code method "isEmpty()" looks like you called it "isBatteryEmpty" always use same names as they asked also in real life ! never use other method names never just never because you will get UML diagram and you have to have same code like on UML diagram

ok sorry i mean ( isBatteryEmpty() ) but the implementation of it is true why i get error ?!

Patrik Horváth
Patrik Horváth
11,110 Points

because "retrun " is not valid you have to use "return"

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 isBatteryEmpty() {
   if( barCount == 0) {
    return true;
   } else {
     return false; 
   }
  }
   public boolean isFullyCharged() {
   if( barCount == MAX_BARS) {
    return true;
   } else {
     return false; 
   }
  }
}

Thanks Patrik it is silly mistake

Patrik Horváth
Patrik Horváth
11,110 Points

dont use TreeHouse code editor use normal IDE it clearly tell you : Syntax error on line 10 for example or when you start type it will show you suggestions for type

for Java try : IntelliJ its best for java + hibernate + sprint + .... in my opinion :)

okay Patrik thanks