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

Gary Burnaska
Gary Burnaska
541 Points

im getting compiler errors out the end, what I am I doing wrong?

Okay, so let's use our new isFullyCharged helper method to change our implementation details of the charge method. Let's make it so it will only charge until the battery reports being fully charged.

Let's use the ! symbol and a while loop. Inside the loop increment mBarsCount.

What am I doing wrong here?

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() { while (!isFullyCharged()) {

  mBarsCount++;      

}

public void charge() { mBarsCount = MAX_ENERGY_BARS; }

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

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

}

3 Answers

George Pirchalaishvili
George Pirchalaishvili
3,747 Points

I think the problem is that you missed 1 "}" in your code. Try this

public void charge() { 
while (!isFullyCharged()) {
  mBarsCount++;      
}
}
Gary Burnaska
Gary Burnaska
541 Points

these are the errors im getting

./GoKart.java:24: error: illegal start of expression public void charge() { ^ ./GoKart.java:24: error: illegal start of expression public void charge() { ^ ./GoKart.java:24: error: ';' expected public void charge() { ^ ./GoKart.java:29: error: illegal start of expression public boolean isBatteryEmpty() { ^ ./GoKart.java:29: error: ';' expected public boolean isBatteryEmpty() { ^ ./GoKart.java:34: error: illegal start of expression public boolean isFullyCharged() { ^ ./GoKart.java:34: error: ';' expected public boolean isFullyCharged() { ^ ./GoKart.java:38: error: reached end of file while parsing } ^ JavaTester.java:71: error: cannot find symbol if (!kart.isBatteryEmpty() || kart.isFullyCharged()) { ^ symbol: method isBatteryEmpty() location: variable kart of type GoKart JavaTester.java:71: error: cannot find symbol if (!kart.isBatteryEmpty() || kart.isFullyCharged()) { ^ symbol: method isFullyCharged() location: variable kart of type GoKart JavaTester.java:76: error: cannot find symbol if (!kart.isFullyCharged()) { ^ symbol: method isFullyCharged() location: variable kart of type GoKart ./GoKart.java:18: error: cannot find symbol while (!isFullyCharged()) { ^ symbol: method isFullyCharged() location: class GoKart ./GoKart.java:30: error: incompatible types: unexpected return value return mBarsCount == 0; ^ ./GoKart.java:35: error: incompatible types: unexpected return value return mBarsCount == MAX_ENERGY_BARS; ^ 14 errors

Gary Burnaska
Gary Burnaska
541 Points

now im just getting this

/GoKart.java:25: error: method charge() is already defined in class GoKart public void charge() {

George Pirchalaishvili
George Pirchalaishvili
3,747 Points

because you forgot to delete your old charge() method :)