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 Computed Properties

Errol Katz
PLUS
Errol Katz
Courses Plus Student 533 Points

How can I make a new similar public method (in this case a boolean method), without overriding the previous method

Every time I try to find a solution and find a similar method, the response is always 'Task 1 is no longer working'. How can I complete this challenge without stopping the first challenge from working?

GoKart.java
class GoKart {
  public static final int MAX_BARS = 8;
  private String color;
  private int barCount;
  public GoKart(String color) {
    this.color = color;
  }
public String getColor() {
    return color;
  }
  public void charge() {
    barCount = MAX_BARS;
} 
public boolean isBatteryEmpty() {
return barCount == 0;
if (barCount == 0)
system.out.println("true");
if (!barCount ==0)
system.out.println("false");
} } {
public boolean isFullyCharged() {
if (barCount = MAX_BARS);
  system.out.println("Fully Charged");
} }

1 Answer

Andrew Boyer
Andrew Boyer
2,733 Points

As soon as you return a value the rest of the code is ignored. The isBatteryEmpty method is expecting to return a boolean (so either true or false). On the first line of isBatteryEmpty you have a return value. Return true or false don't print them.

Errol Katz
Errol Katz
Courses Plus Student 533 Points

Andrew Boyer so how could I go about completing this specific challenge? I.E what code should I use to make it work?