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

Bug in workspace exercise ?

I have followed the video step by step and am receiving an error that says
Example.java 13:error:' ; ' expected dispenser.getCharactername()); ^ Example.java 13:error:' ; ' expected dispenser.getCharactername()); ^

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 is %s %n", dispenser.getCharacterName() ); String before = dispenser.swapHead("Darth Vader"); System.out.printf("It was %s but Chris switched it to %s %n" before, dispenser.getCharacterName() ); }

}

This is the code for the PezDispenser.java file

class PezDispenser { private String characterName;

public PezDispenser(String characterName) { this.characterName = characterName; }

public String getCharacterName() { return characterName; }

public String swapHead(String characterName){ String originalCharacterName = this.characterName; this.characterName = characterName; return originalCharacterName;

} }

1 Answer

Hi Jon I think the main problem is in print out part after Chris switched the dispenser head. You forgot to add comma after the double quotes. It should be like this I think:

System.out.printf("It was %s but Chris switched it to %s %n", before, dispenser.getCharacterName() );

I hope this will help you a little.

Ah thank you it was pretty late so I easily missed this!! That helped so much thank you.