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 Throwing Exceptions

Robert Roberson
PLUS
Robert Roberson
Courses Plus Student 8,401 Points

Ok, I have tried it comes up with errors everytime.

public void drive(int laps) { int not enough battery = laps - mBarsCount; if (not enoungh battery > MAX_BARS){ throw new IllegalArgumentException("Not enough Battery"); } This is what I understod from the video.

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 void drive() {
    drive(1);
  }
 public void drive(int laps) {
    int not enough battery = laps - mBarsCount;
    if (not enoungh battery > MAX_BARS){
    throw new IllegalArgumentException("Not enough Battery");
    }

  public void charge() {
    while (!isFullyCharged()) {
      mBarsCount++;
    }
  }

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

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

}

7 Answers

Ilya Dolgirev
Ilya Dolgirev
35,375 Points

Check this topic.

Hope it will help you to solve your problem :)

Robert Roberson
PLUS
Robert Roberson
Courses Plus Student 8,401 Points

Thanks for the message. Could you explain how I was to divine that from the video?

Ilya Dolgirev
Ilya Dolgirev
35,375 Points

Frankly, I believe it's just a common logic. You can't give me something if you don't have it. In this case, imho, it's obvious to check the battery level before driving.

BTW, not some concepts and ideas understandable from the first time. It's absolutely normal. Just take a quick break, try to solve it once again. If you got the same thing - ask for help. It's also absolutely normal :)

Robert Roberson
PLUS
Robert Roberson
Courses Plus Student 8,401 Points

Yes, except that method hasn't really been working for me. I just muddle along not seeing the logic and not completely understanding what is going on and sort just going through the pacing while other people tell me "you should do this." But, none of them are capable of explaining where I went wrong. Other than answers like "it is pretty logical what has to be done." and I am sure from your point of view it is. But I am still learning this. And I thought this forum was about learning. But it seems to be more about knowing and proving to those who don't, how much one knows and how much the other doesn't.

Ilya Dolgirev
Ilya Dolgirev
35,375 Points

NP, you're welcome! Good luck with Java :)