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 Abstraction at Play

aden ajayi
aden ajayi
552 Points

Example.java:21: error: reached end of file while parsing

Not sure all my braces seem to be in the right place but i keep getting Example.java:21: error: reached end of file while parsing

public class Example {

public static void main(String[] args) { // Your amazing code goes here... System.out.println("we are making a new pez dispenser"); System.out.printf("FUN FACT: there are %d Pez allowed in every dispenser%n", PezDispenser.MAX_PEZ); PezDispenser dispenser = new PezDispenser ("Hisoka"); { System.out.printf ("the Dispenser is %s %n", dispenser.getCharacterName() ); } if (dispenser.isEmpty()) { System.out.println ("Dispenser is empty"); } System.out.println("Filling the despenser with the good stuff..."); dispenser.fill(); if (!dispenser.isEmpty()){ System.out.println("Dispenser is full"); }

}

4 Answers

You're very very close ! I've put the code in a Java format so you can read it back. Very carefully re-examine this code and see where you went wrong. You are on the right track. It has to do with curly braces.

Small hint below. Look at the structure with the curly braces.

     if (condition) { 
          //Do something... Like
          System.out.println ("Some challenge with dispensers"); 
          }
public static void main(String[] args) {

 // Your amazing code goes here... 

     System.out.println("we are making a new pez dispenser"); 
     System.out.printf("FUN FACT: there are %d Pez allowed in every dispenser%n", PezDispenser.MAX_PEZ); 
     PezDispenser dispenser = new PezDispenser ("Hisoka"); 
     { System.out.printf ("the Dispenser is %s %n", dispenser.getCharacterName() ); } 

     if (dispenser.isEmpty()) { System.out.println ("Dispenser is empty"); }
          System.out.println("Filling the despenser with the good stuff..."); 
          dispenser.fill(); 

     if (!dispenser.isEmpty()){ 
        System.out.println("Dispenser is full"); 
     }

}

If you need more help, do ask :) !

aden ajayi
aden ajayi
552 Points

I still don't see whats wrong am I missing a curly brace is it in the wrong place?

aden ajayi I really don't want to give it away. But yes it is in that direction :) This part of figuring out whats wrong will really help you in the future.

public class Example {
public static void main(String[] args) {

System.out.println("We are making a new PEZ Dispenser");
System.out.printf("FUN FACT: There are %d PEZ allowed in every dispenser%n",
                  PezDispenser.MAX_PEZ);

PezDispenser dispenser = new PezDispenser("Yoda"); 
 { System.out.printf("The dispenser is %s %n", dispenser.getCharacterName() ); }

if (dispenser.isEmpty() )
 { System.out.println("Dispenser is empty"); }     
   System.out.println("Filling the dispenser with delicious PEZ..");   
   dispenser.fill();

if (!dispenser.isEmpty() ) 
 { System.out.println("Dispenser is full"); }

} }

I've made the setup look cleaner so it can be easier for me to read in future lessons. I think I was missing a bracket or something.

{ public class Example {
public static void main(String[] args) {

System.out.println("We are making a new PEZ Dispenser");
System.out.printf("FUN FACT: There are %d PEZ allowed in every dispenser%n",
                  PezDispenser.MAX_PEZ);

PezDispenser dispenser = new PezDispenser("Yoda"); 
 { System.out.printf("The dispenser is %s %n", dispenser.getCharacterName() ); }

if (dispenser.isEmpty() )
 { System.out.println("Dispenser is empty"); }     
   System.out.println("Filling the dispenser with delicious PEZ..");   
   dispenser.fill();

if (!dispenser.isEmpty() ) 
 { System.out.println("Dispenser is full"); }

} } }

How do I delete the comments?