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 Helper Methods and Conditionals

Whitney Barber
Whitney Barber
9,453 Points

Java, I can't get my Pez Dispenser object to work.

I activate repl and it loads correctly. I then enter the command "PezDispenser pd = new PezDispenser("Yoda");" and get back this message...

java.util.NoSuchElelmentException

Here is my code...

public class PezDispenser { public static final int MAX_PEZ = 12; private String mCharacterName; private int mPezCount;

public PezDispenser(String characterName) { mCharacterName = characterName; mPezCount = 0; }

public boolean isEmpty(); { return mPezCount == 0; }

public String getCharacterName() { return mCharacterName; }

public void load(); { mPezCount = MAX_PEZ; }

}

Please assist, thank you.

2 Answers

Christopher Augg
Christopher Augg
21,223 Points

Whitney,

Almost got this perfect! Just a few extra semicolons in the wrong place. Look at your isEmpty and load method.

       public boolean isEmpty(); { return mPezCount == 0; }

       public void load(); { mPezCount = MAX_PEZ; }

Which semicolon does not belong in those?

Hope this helps.

Regards,

Chris

Priyesh Tungare
Priyesh Tungare
13,168 Points

Hi Whitney,

As pointed out by Chirstopher, please remove the extra semi-colons from your method declaration.

Also. to load your class in REPL, use the command :load PezDispenser.java in your REPL console.

Hope this helps.

Regards, Priyesh "Never Stop Learning"