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

greer zimmerman
greer zimmerman
414 Points

When I "make a new Pez Dispenser" in Example.java, does not print out everything

When I create a new pez dispenser in Example.java, it does not first print out "We are making a new Pez Dispenser. The dispenser character is Yoda." It skips straight to "it is currently empty. Loading... It is no longer empty."

Is there something wrong in my PezDispenser.java file?

This is what my code looks like for Example.java:

public class Example {

    public static void main(String[] args) {
        // Your amazing code goes here...
        System.out.println ("We are making a new pez dispenser");
        PezDispenser dispenser = new PezDispenser("Yoda");
        System.out.printf("The dispenser character is %s\n",
                          dispenser.getCharacterName());
     if (dispenser.isEmpty()) {
       System.out.println("It is currently empty");
     }
      System.out.println("loading...");
      dispenser.load();
      if (!dispenser.isEmpty()) {
        System.out.println("It is no longer empty");
      }

    }
}

1 Answer

Simon Coates
Simon Coates
28,694 Points

I copied your java code, saved, recompiled and executed:

treehouse:~/workspace$ javac Example.java                                              
treehouse:~/workspace$ javac PezDispenser.java                                         
treehouse:~/workspace$ javac Example.java                                              
treehouse:~/workspace$ java Example                                                    
We are making a new pez dispenser                                                      
The dispenser character is Yoda                                                        
It is currently empty                                                                  
loading...                                                                             
It is no longer empty                                                                  
treehouse:~/workspace$