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 Helper Methods

Roger Vieira
Roger Vieira
3,138 Points

Now create a helper method named isFullyCharged. It should return true if the GoKart is at max capacity.

Yeah I'm sure I'm doing this assignment correctly....but it's telling me I've got a compiler error!?

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

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

  public String getColor() {
    return mColor;
  }

 public boolean isBatteryEmpty(){
  if (mBarsCount<=0){

     return true;
  } 

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

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

1 Answer

Alexander Nikiforov
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Alexander Nikiforov
Java Web Development Techdegree Graduate 22,175 Points

When you check your challenge, please post here also push "Preview" button. It shows you errors that you do:

If you paste your code and after Error, hit "Preview button", you will see the following output:

/GoKart.java:22: error: illegal start of expression
   public boolean isFullyCharged(){
   ^
./GoKart.java:22: error: ';' expected
   public boolean isFullyCharged(){
                                ^
./GoKart.java:26: error: illegal start of expression
  public void charge() {
  ^
./GoKart.java:26: error: illegal start of expression
  public void charge() {
         ^
./GoKart.java:26: error: ';' expected
  public void charge() {
                    ^
./GoKart.java:29: error: reached end of file while parsing
}
 ^
JavaTester.java:89: error: cannot find symbol
  kart.charge();
      ^
  symbol:   method charge()
  location: variable kart of type GoKart
7 errors

As you can see the first error is the illegal start of expression. You have to go to the line "22" and take a look if everything is OK...

Illegal start of expression means you cannot write public, and you cannot write public because you haven't close your public boolean isBatteryEmpty() { method.

And because it is not closed with brace '}' compiler cannot proceed to the next method :isFullyCharged.

Fix that and try to catch another error:) And make sure you check errors after hitting Preview button.

The second error should be straightforward to fix.