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

Asaf ahmed
Asaf ahmed
461 Points

help please. 12 errors

''' 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 good PEZ");
dispenser.fill();

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

} if (dispenser.isEmpty()) { System.out.println("ate all the pEz");

}''' console: '''Picked up JAVA_TOOL_OPTIONS: -Xmx128m
Picked up _JAVA_OPTIONS: -Xmx128m
Example.java:25: error: illegal start of type
while (dispenser.dispense()) {
^
Example.java:25: error: <identifier> expected
while (dispenser.dispense()) {
^
Example.java:25: error: ';' expected
while (dispenser.dispense()) {
^
Example.java:25: error: illegal start of type
while (dispenser.dispense()) {
^
Example.java:25: error: <identifier> expected
while (dispenser.dispense()) {
^
Example.java:25: error: ';' expected
while (dispenser.dispense()) {
^
Example.java:26: error: illegal start of type
System.out.println("Chomp!");
^
Example.java:26: error: ';' expected
System.out.println("Chomp!");
^
Example.java:26: error: invalid method declaration; return type required
System.out.println("Chomp!");
^
Example.java:26: error: illegal start of type
System.out.println("Chomp!");
^
Example.java:29: error: class, interface, or enum expected
}
^
Example.java:35: error: class, interface, or enum expected '''

1 Answer

Hi Asaf,

I've gone through your code, and taken a look. (On a side note if you use 3 back ticks and type Java before your code and use 3 back ticks afterwards your code will be formatted like mine below).

I use Java everyday but I'll admit to not having gone through this bit of Treehouse so I don't know if all the methods are correct but it looked to me like you simply misplaced some curly braces. Using proper indentation can help catch these errors.

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 good PEZ");
    dispenser.fill();

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

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

    if (dispenser.isEmpty()) { 
        System.out.println("ate all the pEz");
    }
}

Hope this helps Daniel