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 Incrementing

I am unable to understand this challenge. Please help me over here.

I am not good with Java but I am trying to learn it. Can someone please explain me this question and tell me how to do it. Really appreciate it.

2 Answers

Talmage Shill
PLUS
Talmage Shill
Courses Plus Student 7,593 Points

It's asking you to change the way the charge function is implemented. Currently, it just replaces the current charge with the max, but that isn't how it works in the real world. In the real world, charging take a while and should only occur when levels are low (Some batteries break if you over-charge them). The challenge is asking you simulate the real world by creating a loop that checks if its done charging. If it isn't, then increment the current charge level by 1.

The GoKart class has a handy method that returns True if the GoKart is fully charged. Because the charge loop should only run when the GoKart is not charge, we can use the ! operator in the while-loop's condition.

while(!isFullyCharged()){
    mBarsCount++; // mBarsCount = mBarsCount+1;
}

I hope this helps. Let me know if there is anything else I can clarify.

Thanks Talmage Shill