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 Exceptions

Question about the challenge

in the video, Craig had to put pezCount = newAmount in order for the code to work, but in the challenge itself:

public void drive (int laps) {
int lapsAmount = barCount - laps;
if (lapsAmount < 0) {
throw new IllegalArgumentException ("Battery finished");
}
}

I wrote without barCount = lapsAmount and it worked. Is it something wrong with the exercise, or I didn't fully understand the concept?

2 Answers

i don’t understand what is your question , ur implemention looks ok, u store the amount of laps into lapsAmoint,

I just dont understand why in Craig's case is necessary, and in mine is not

Hi it is different because the drive() method does something different.

In the video, the fill() method takes in pezAmount parameter and assigns it to pezCount

In the challenge, the drive() method takes in laps parameter and adds to lapsDriven and subtracts it from barCount