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 Method Overloading

Magnus Dilling Pettersen
Magnus Dilling Pettersen
5,681 Points

Why am I only getting two PEZ, when I should have gotten six?

    dispenser.fill(4);
    dispenser.fill(2);
    while (dispenser.dispense()) {
      System.out.println("Chomp!!");
    }

1 Answer

What does your dispenser fill method look like? When you call the fill method if the param added to the pez count or set to the pez count. When you call fill the pez count should increase by the amount param.

public void fill(int pezAmount) {
    pezCount += pezAmount;
}

If you are not getting chomp to print out 6 times it might be because your method looks like this.

public void fill(int pezAmount) {
    pezCount = pezAmount;
}