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 Changing State

Michael Werlinger
Michael Werlinger
1,259 Points

Now create a method named charge that sets the new barCount field to the maximum amount of bars available for each GoKar

class GoKart {
    public static final int MAX_BARS = 8;
    private String color;
    private int barCount;   // <-- right there is step bloody 1

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

    public String getColor() {
         return color;
    }

    public charge void() {      // ok I don't get it, it wants a new method named charged....ok
        barCount = MAX_BARS;  // now set the new barCount field to MAX_BARS
    }

}

but surprise surprise it don't work

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 charge void() {
    barCount = MAX_BARS;
  }

}

2 Answers

andren
andren
28,558 Points

The issue is in your method declaration:

public charge void()

The return type (void) has to be placed before the name of the method, not after. So if you simply flip the name and return type around like this:

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() { // Flip void and charge
    barCount = MAX_BARS;
  }
}

Then your code will work.

Michael Werlinger
Michael Werlinger
1,259 Points

Thank you so much! I am slightly embarrassed I did that lol