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 Increment and Decrement

Steve Wofford
Steve Wofford
2,485 Points

Task 1 works, but then task 2 says task 1 doesn't work right after.

When i start the first tasks. it ask me to give a private int lapDriven. I did just that and it works. Then when i get to task 2, and i try putting in the next increments, the challenge says task 1 is no longer passing. How? Every time i go back to task 1, it works and goes to task 2 it wants me to go back to task one. Can someone please help me understand?

GoKart.java
class GoKart {
  public static final int MAX_BARS = 8;
  private String color;
  private int barCount;
  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(int laps) {
    if(laps > barCount){
      throw new IllegalArgumentException();
    } else {
      lapsDriven += laps;
      barCount -= laps;

2 Answers

Jennifer Nordell
seal-mask
STAFF
.a{fill-rule:evenodd;}techdegree
Jennifer Nordell
Treehouse Teacher

Hi there! Generally speaking, when it says that a previous task is no longer working, it's because you've introduced a syntax error into your code that wasn't present before. There can be other causes for this, but this is the primary reason you would receive this message.

Just glancing at your code that's posted here, I can tell you that you're missing no less than 2 closed curly braces/curly brackets. Check the last drive method. Each open curly brace/curly bracket should have a matching closed one.

Hope this helps, but let me know if you're still stuck! :sparkles:

Steve Wofford
Steve Wofford
2,485 Points

Ive added the 2 brackets and still tells me the first task is no longer passing. The reason i know it isn't a syntax error is because when i check my work on task 2 even before adding anymore code, it stills says task 1 is no longer working. How does it not work when it just worked on task 1?

Jennifer Nordell
seal-mask
.a{fill-rule:evenodd;}techdegree
Jennifer Nordell
Treehouse Teacher

Can you please post the code you're currently trying? I'd like to take a better look at it after you've added the closed braces/brackets.

Steve Wofford
Steve Wofford
2,485 Points

Ive figured something out by some of the other forums. I appreciate the help!

Jacob Klug
Jacob Klug
469 Points

Did craig teach us about throw new or else yet because I dont recover learning about any of that especially the throw new code