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

taha siddiqui
taha siddiqui
6,222 Points

what is going on

Can someone please explain the answer in non-complicated language? Thanks guys. Really frustrated because I have been on this code for like 20 minutes just repeatedly changing stuff but it never turns out right

Example.java
class Example {

  public static void main(String[] args) {
    GoKart kart = new GoKart("purple");
    if (kart.isBatteryEmpty()) {
      System.out.println("The battery is empty");
    }
    try {
      kart.drive(42);
    } catch (IllegalArgumentException iae) {
      System.out.println("*******");
    }
  }

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

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

  public String getColor() {
    return color;
  }

  public void charge() {
    barCount = MAX_BARS;
  }

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

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

  public void drive() {
    drive(1);
  }

  public void drive(int laps) {
    if (laps > barCount) {
      throw new IllegalArgumentException("Not enough battery remains");
    }
    lapsDriven += laps;
    barCount -= laps;
  }

}

Moderator Edit: Modified title of post and omitted inappropriate language. Please watch language in the Community as students of all ages and backgrounds use it. Thank-you

Kurt Bitner
Kurt Bitner
12,135 Points

Are you getting an illegal expression error? That is happening with all java code challenges apparently. There is a major issue.

Jason Anders
Jason Anders
Treehouse Moderator 145,860 Points

Hi taha siddiqui

While learning can often be frustrating, the language in your title and in your post, which I have redacted, is not acceptable in the Treehouse Community. Please refer to the Community's Code of Conduct if you have any questions regarding expectations for conduct in the Forums.

Thank-you.

Jason Anders ~Treehouse Community Moderator

1 Answer

Jason Anders
MOD
Jason Anders
Treehouse Moderator 145,860 Points

To add to Kurt Bitner ...

There seems to be some technical issues with the Java challenges. I'm sure the Support Team is on top of this. For now, you can always continue with the course and come back to the Challenges later on, once the problem has been corrected with the Code Checkers. This can be done by manually navigating your progress using the nav links above the video window.

:dizzy:

taha siddiqui
taha siddiqui
6,222 Points

yea exactly, I have noticed this for quite a bit of time. Even the hints sort of are never good. In the code for thee challenges, there are only one or two variations of hints and a syntax error which most of the time isn't really one. Also, if there is an error or something wrong and I press submit, it spits out like 20 lines of code with like 20 error messages of stuff I basically don't understand. Thanks for verifying this though