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 Incrementing

Fully charged gokart

I am now totally lost here

GoKart.java
public class GoKart {
  public static final int MAX_ENERGY_BARS = 8;
  private String mColor;
  private int mBarsCount;

  public GoKart(String color) {
    mColor = color;
    mBarsCount = 0;
  }

  public String getColor() {
    return mColor;
  }

  public void charge() {
    mBarsCount = MAX_ENERGY_BARS;
  }

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

  public boolean isFullyCharged() {
    return mBarsCount == MAX_ENERGY_BARS;
     boolean isFullyCharged = false;
    System.out.println ("Charging");}
     if (!isFullyCharged()){
   mBarsCount++;
     isFullyCharged = true;
     while(!isFullyCharged()){
       mBarsCount++;
     }
     if (isFullyCharged()){
      System.out.println("Is fully charged"); 
     }
   }
   return isFullyCharged;
  }
  }

1 Answer

Ok one thing at a time.

Firstly, you are writing your code inside the wrong scope of a method. The task says to USE the isFullycharged method, not change it.

Secondly, you cannot have two "return" statements in a single method, unless they are logically separated (for example and if/else clause).

Thirdly, it seems to me that you have just added random thoughts into the method and hoped for the best. Did you try to understand the method and it's purpose? Did you think about what it should do in every step?

Finally, go back and read the given task again. You shouldn't add things that are not required (yes it may not interfere with the task or with the program as a whole, but in the real world it may be a problem if you do things you're not asked to do). Neither "if" nor "printf" are required for the task, so remove them. The code required from you is 3 lines exactly. Think about them and what they should do. How they work, why do they work in the way they do, etc. And try to pay more attention in the future.

I know the comment seemed more like a destructive criticism rather than constructive, but I think you should be more careful. Get some sleep if that's the problem, go eat, if needed. It's important to take short breaks every now and then. Let your mind relax. You're not here to become a machine. Take care :)

Best wishes, Kristian